using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using BA;
using BA.DAL;

namespace BlazeApps.Library
{
    public class Procedures : ConfigSettings
    {
        private BA.DAL.DBUtility DAL = new BA.DAL.DBUtility();

        #region "MSSQL/MySQL Blog Procedure Properties "

        public StringBuilder GetBlogByBlogID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("blogid, ");
                Proc.Append("title, ");
                Proc.Append("body, ");
                Proc.Append("userid, ");
                Proc.Append("createdate, ");
                Proc.Append("private, ");
                Proc.Append("dbo.fn_comment_count(blogid) as comments, ");
                Proc.Append("dbo.fn_view_count(blogid) as views, ");
                Proc.Append("IsNull(dbo.fn_rank_count(blogid), 0) as rank ");
                Proc.Append("FROM blog ");
                Proc.Append("WHERE blogid = @blogid ");

                return FormatSQLStateMents(Proc);

            }
        }

        public StringBuilder InsertBlog
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("INSERT INTO blog ");
                Proc.Append("( ");
                Proc.Append("blogid, ");
                Proc.Append("title, ");
                Proc.Append("body, ");
                Proc.Append("userid, ");
                Proc.Append("createdate, ");
                Proc.Append("private ");
                Proc.Append(") VALUES ( ");
                Proc.Append("@blogid, ");
                Proc.Append("@title, ");
                Proc.Append("@body, ");
                Proc.Append("@userid, ");
                Proc.Append("@createdate, ");
                Proc.Append("@private ");
                Proc.Append(") ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder UpdateBlog
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("UPDATE blog SET ");
                Proc.Append("title = @title, ");
                Proc.Append("body = @body, ");
                Proc.Append("private = @private ");
                Proc.Append("WHERE blogid = @blogid ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder DeleteBlog
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("DELETE FROM blog WHERE blogid = @blogid");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListBlogs
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("blogid, ");
                Proc.Append("title, ");
                Proc.Append("body, ");
                Proc.Append("userid, ");
                Proc.Append("createdate, ");
                Proc.Append("private, ");
                Proc.Append("dbo.fn_comment_count(blogid) as comments, ");
                Proc.Append("dbo.fn_view_count(blogid) as views, ");
                Proc.Append("IsNull(dbo.fn_rank_count(blogid), 0) as rank ");
                Proc.Append("FROM blog ");
                Proc.Append("WHERE private = 0 ");

                return FormatSQLStateMents(Proc);

            }
        }

        public StringBuilder ListBlogsByUser
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("blogid, ");
                Proc.Append("title, ");
                Proc.Append("body, ");
                Proc.Append("userid, ");
                Proc.Append("createdate, ");
                Proc.Append("private, ");
                Proc.Append("dbo.fn_comment_count(blogid) as comments, ");
                Proc.Append("dbo.fn_view_count(blogid) as views, ");
                Proc.Append("IsNull(dbo.fn_rank_count(blogid), 0) as rank ");
                Proc.Append("FROM blog ");
                Proc.Append("WHERE userid = @userid ");
                Proc.Append("and private = 0 ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListBlogsByDate
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("blogid, ");
                Proc.Append("title, ");
                Proc.Append("body, ");
                Proc.Append("userid, ");
                Proc.Append("createdate, ");
                Proc.Append("private, ");
                Proc.Append("dbo.fn_comment_count(blogid) as comments, ");
                Proc.Append("dbo.fn_view_count(blogid) as views, ");
                Proc.Append("IsNull(dbo.fn_rank_count(blogid), 0) as rank ");
                Proc.Append("FROM blog ");
                Proc.Append("WHERE createdate = @date ");
                Proc.Append("and private = 0 ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListBlogsByMonthYear
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                if(Provider == DBUtility.Providers.SqlServer)
                {
                    Proc.Append("SELECT ");
                    Proc.Append("blogid, ");
                    Proc.Append("title, ");
                    Proc.Append("body, ");
                    Proc.Append("userid, ");
                    Proc.Append("createdate, ");
                    Proc.Append("private, ");
                    Proc.Append("dbo.fn_comment_count(blogid) as comments, ");
                    Proc.Append("dbo.fn_view_count(blogid) as views, ");
                    Proc.Append("IsNull(dbo.fn_rank_count(blogid), 0) as rank ");
                    Proc.Append("FROM blog ");
                    Proc.Append("WHERE datepart(m, createdate) = @month  ");
                    Proc.Append("and datepart(yyyy, createdate) = @year ");
                    Proc.Append("and private = 0 ");
                }

                if(Provider == DBUtility.Providers.MySQL)
                {
                    Proc.Append("SELECT ");
                    Proc.Append("blogid, ");
                    Proc.Append("title, ");
                    Proc.Append("body, ");
                    Proc.Append("userid, ");
                    Proc.Append("createdate, ");
                    Proc.Append("private, ");
                    Proc.Append("dbo.fn_comment_count(blogid) as comments, ");
                    Proc.Append("dbo.fn_view_count(blogid) as views, ");
                    Proc.Append("IsNull(dbo.fn_rank_count(blogid), 0) as rank ");
                    Proc.Append("FROM blog ");
                    Proc.Append("WHERE MONTH(createdate) = @month  ");
                    Proc.Append("and YEAR(createdate) = @year ");
                    Proc.Append("and private = 0 ");
                }

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListBlogsByUserMonthYear
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                if(Provider == DBUtility.Providers.SqlServer)
                {

                    Proc.Append("SELECT ");
                    Proc.Append("blogid, ");
                    Proc.Append("title, ");
                    Proc.Append("body, ");
                    Proc.Append("userid, ");
                    Proc.Append("createdate, ");
                    Proc.Append("private, ");
                    Proc.Append("dbo.fn_comment_count(blogid) as comments, ");
                    Proc.Append("dbo.fn_view_count(blogid) as views, ");
                    Proc.Append("IsNull(dbo.fn_rank_count(blogid), 0) as rank ");
                    Proc.Append("FROM blog ");
                    Proc.Append("WHERE userid = @userid  ");
                    Proc.Append("and datepart(m, createdate) = @month  ");
                    Proc.Append("and datepart(yyyy, createdate) = @year ");
                    Proc.Append("and private = 0 ");
                }

                if(Provider == DBUtility.Providers.MySQL)
                {

                    Proc.Append("SELECT ");
                    Proc.Append("blogid, ");
                    Proc.Append("title, ");
                    Proc.Append("body, ");
                    Proc.Append("userid, ");
                    Proc.Append("createdate, ");
                    Proc.Append("private, ");
                    Proc.Append("dbo.fn_comment_count(blogid) as comments, ");
                    Proc.Append("dbo.fn_view_count(blogid) as views, ");
                    Proc.Append("IsNull(dbo.fn_rank_count(blogid), 0) as rank ");
                    Proc.Append("FROM blog ");
                    Proc.Append("WHERE userid = @userid  ");
                    Proc.Append("and MONTH(createdate) = @month  ");
                    Proc.Append("and YEAR(createdate) = @year ");
                    Proc.Append("and private = 0 ");
                }

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListBlogsPeriodCount
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                if(Provider == DBUtility.Providers.SqlServer)
                {
                    Proc.Append("SELECT ");
                    Proc.Append("datepart(m, createdate) as blogmonth, ");
                    Proc.Append("datepart(yy, createdate) as blogyear, ");
                    Proc.Append("dbo.fn_blog_count(datepart(m, createdate), datepart(yy, createdate)) as blogcount  ");
                    Proc.Append("FROM blog ");
                    Proc.Append("GROUP BY datepart(m, createdate), datepart(yy, createdate) ");
                    Proc.Append("ORDER BY datepart(yy, createdate) DESC, datepart(m, createdate) DESC ");
                }

                if(Provider == DBUtility.Providers.MySQL)
                {
                    Proc.Append("SELECT ");
                    Proc.Append("MONTH(createdate) as blogmonth, ");
                    Proc.Append("YEAR(createdate) as blogyear, ");
                    Proc.Append("dbo.fn_blog_count(MONTH(createdate), YEAR(createdate)) as blogcount  ");
                    Proc.Append("FROM blog ");
                    Proc.Append("GROUP BY MONTH(createdate), YEAR(createdate) ");
                    Proc.Append("ORDER BY YEAR(createdate) DESC, MONTH(createdate) DESC ");
                }

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListBlogsPeriodCountByUser
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                if(Provider == DBUtility.Providers.SqlServer)
                {
                    Proc.Append("SELECT ");
                    Proc.Append("datepart(m, createdate) as blogmonth, ");
                    Proc.Append("datepart(yy, createdate) as blogyear, ");
                    Proc.Append("dbo.fn_blog_count(datepart(m, createdate), datepart(yy, createdate)) as blogcount  ");
                    Proc.Append("FROM blog ");
                    Proc.Append("WHERE userid = @userid ");
                    Proc.Append("GROUP BY datepart(m, createdate), datepart(yy, createdate) ");
                    Proc.Append("ORDER BY datepart(yy, createdate) DESC, datepart(m, createdate) DESC ");
                }

                if(Provider == DBUtility.Providers.MySQL)
                {
                    Proc.Append("SELECT ");
                    Proc.Append("MONTH(createdate) as blogmonth, ");
                    Proc.Append("YEAR(createdate) as blogyear, ");
                    Proc.Append("dbo.fn_blog_count(MONTH(createdate), YEAR(createdate)) as blogcount  ");
                    Proc.Append("FROM blog ");
                    Proc.Append("WHERE userid = @userid ");
                    Proc.Append("GROUP BY MONTH(createdate), YEAR(createdate) ");
                    Proc.Append("ORDER BY YEAR(createdate) DESC, MONTH(createdate) DESC ");
                }

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListMyBlogs
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                if(Provider == DBUtility.Providers.SqlServer)
                {
                    Proc.Append("SELECT ");
                    Proc.Append("blogid, ");
                    Proc.Append("title, ");
                    Proc.Append("body, ");
                    Proc.Append("userid, ");
                    Proc.Append("createdate, ");
                    Proc.Append("private, ");
                    Proc.Append("dbo.fn_comment_count(blogid) as comments, ");
                    Proc.Append("dbo.fn_view_count(blogid) as views, ");
                    Proc.Append("IsNull(dbo.fn_rank_count(blogid), 0) as rank ");
                    Proc.Append("FROM ");
                    Proc.Append("blog ");
                    Proc.Append("WHERE userid = @userid ");
                    Proc.Append("and datepart(m, createdate) = @month  ");
                    Proc.Append("and datepart(yyyy, createdate) = @year ");
                }

                if(Provider == DBUtility.Providers.MySQL)
                {
                    Proc.Append("SELECT ");
                    Proc.Append("blogid, ");
                    Proc.Append("title, ");
                    Proc.Append("body, ");
                    Proc.Append("userid, ");
                    Proc.Append("createdate, ");
                    Proc.Append("private, ");
                    Proc.Append("dbo.fn_comment_count(blogid) as comments, ");
                    Proc.Append("dbo.fn_view_count(blogid) as views, ");
                    Proc.Append("IsNull(dbo.fn_rank_count(blogid), 0) as rank ");
                    Proc.Append("FROM ");
                    Proc.Append("blog ");
                    Proc.Append("WHERE userid = @userid ");
                    Proc.Append("and MONTH(createdate) = @month  ");
                    Proc.Append("and YEAR(createdate) = @year ");
                }

                return FormatSQLStateMents(Proc);

            }
        }

        public StringBuilder SearchAllBlogs
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("blogid, ");
                Proc.Append("title, ");
                Proc.Append("body, ");
                Proc.Append("userid, ");
                Proc.Append("createdate, ");
                Proc.Append("private, ");
                Proc.Append("dbo.fn_comment_count(blogid) as comments, ");
                Proc.Append("dbo.fn_view_count(blogid) as views, ");
                Proc.Append("IsNull(dbo.fn_rank_count(blogid), 0) as rank ");
                Proc.Append("FROM blog ");
                Proc.Append("WHERE private = 0 ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder SearchBlogsByUser
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("blogid, ");
                Proc.Append("title, ");
                Proc.Append("body, ");
                Proc.Append("userid, ");
                Proc.Append("createdate, ");
                Proc.Append("private, ");
                Proc.Append("dbo.fn_comment_count(blogid) as comments, ");
                Proc.Append("dbo.fn_view_count(blogid) as views, ");
                Proc.Append("IsNull(dbo.fn_rank_count(blogid), 0) as rank ");
                Proc.Append("FROM blog ");
                Proc.Append("WHERE userid = @userid ");
                Proc.Append("and private = 0 ");

                return FormatSQLStateMents(Proc);
            }
        }

        #endregion

        #region "MSSQL/MySQL Category Procedure Properties "

        public StringBuilder GetCategoryByItemID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ic.categoryid, c.name ");
                Proc.Append("FROM item_categories as ic ");
                Proc.Append("JOIN categories as c on c.categoryid = ic.categoryid ");
                Proc.Append("WHERE ic.itemid = @itemid and (archived = 0 or archived is null) ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder InsertCategory
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("INSERT INTO categories ");
                Proc.Append("( ");
                Proc.Append("categoryid, ");
                Proc.Append("parentcategoryid, ");
                Proc.Append("name ");
                Proc.Append(")  ");
                Proc.Append("VALUES ");
                Proc.Append("( ");
                Proc.Append("@categoryid, ");
                Proc.Append("@parentcategoryid, ");
                Proc.Append("@name ");
                Proc.Append(") ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder UpdateCategory
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("IF @parentcategoryid Is Null ");
                Proc.Append("UPDATE categories  ");
                Proc.Append("SET name = @name ");
                Proc.Append("WHERE categoryid = @categoryid ");
                Proc.Append("ELSE ");
                Proc.Append("BEGIN ");
                Proc.Append("UPDATE categories  ");
                Proc.Append("SET parentcategoryid = @parentcategoryid, name = @name ");
                Proc.Append("WHERE categoryid = @categoryid ");
                Proc.Append("END ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder DeleteCategory
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("UPDATE categories SET archived = @archived WHERE categoryid = @categoryid");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListCategories
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("categoryid, ");
                Proc.Append("parentcategoryid, ");
                Proc.Append("name, ");
                Proc.Append("createdate, ");
                Proc.Append("archived  ");
                Proc.Append("FROM categories ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListCategoriesByItemID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("c.categoryid, ");
                Proc.Append("c.parentcategoryid, ");
                Proc.Append("c.name, ");
                Proc.Append("c.createdate, ");
                Proc.Append("c.archived ");
                Proc.Append("FROM item_categories as ic ");
                Proc.Append("JOIN categories as c on c.categoryid = ic.categoryid ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder GetCategoryChildByParentID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT c.categoryid as nodeid, name, ");
                Proc.Append("(SELECT count(*) FROM categories WHERE parentcategoryid=c.categoryid) as childnodecount ");
                Proc.Append("FROM categories c ");
                Proc.Append("WHERE parentcategoryid = @parentnodeid ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder GetCategoryParent
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT c.categoryid as nodeid, name, ");
                Proc.Append("(SELECT count(*) FROM categories WHERE parentcategoryid=c.categoryid) as childnodecount ");
                Proc.Append("FROM categories c ");
                Proc.Append("WHERE parentcategoryid IS NULL ");

                return FormatSQLStateMents(Proc);
            }
        }

        #endregion

        #region "MSSQL/MySQL Comments Procedure Properties "

        public StringBuilder GetCommentsByItemID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT dbo.fn_comment_count(@itemid) as commentcount, comments ");
                Proc.Append("FROM comments  ");
                Proc.Append("WHERE itemid = @itemid ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder InsertComment
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("INSERT INTO comments ");
                Proc.Append("( ");
                Proc.Append("id, ");
                Proc.Append("itemid, ");
                Proc.Append("userid, ");
                Proc.Append("subject, ");
                Proc.Append("comments, ");
                Proc.Append("parentid ");
                Proc.Append(") ");
                Proc.Append("VALUES ");
                Proc.Append("(	 ");
                Proc.Append("@id, ");
                Proc.Append("@itemid, ");
                Proc.Append("@userid, ");
                Proc.Append("@subject, ");
                Proc.Append("@comments, ");
                Proc.Append("@parentid ");
                Proc.Append(") ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder UpdateComment
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("UPDATE comments  ");
                Proc.Append("SET comments = @comments ");
                Proc.Append("WHERE id = @Commentid ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder DeleteComment
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("DELETE FROM comments WHERE ID = @Commentid");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListCommentsByItemID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT id, parentid, userid, comments, createdate, subject ");
                Proc.Append("FROM comments ");
                Proc.Append("WHERE itemid = @itemid ");
                Proc.Append("and (archived is null or archived = 0) ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListCommentChildByParentID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                if(Provider == DBUtility.Providers.SqlServer)
                {
                    Proc.Append("SELECT id, parentid, userid, comments, createdate, subject, ");
                    Proc.Append("(SELECT count(*) FROM comments WHERE parentid=c.id) as childnodecount ");
                    Proc.Append("FROM comments as c ");
                    Proc.Append("WHERE parentid = @parentid and (archived = 0 or archived is null) ");
                }

                if(Provider == DBUtility.Providers.MySQL)
                {
                    Proc.Append("SELECT id, parentid, userid, comments, createdate, subject, ");
                    Proc.Append("fn_comment_child_count(id) as childnodecount ");
                    Proc.Append("FROM comments ");
                    Proc.Append("WHERE parentid = @parentid and (archived = 0 or archived is null) ");
                }

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListCommentParent
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                if(Provider == DBUtility.Providers.SqlServer)
                {
                    Proc.Append("SELECT id, parentid, userid, comments, createdate, subject, ");
                    Proc.Append("(SELECT count(*) FROM comments WHERE parentid=c.id) as childnodecount ");
                    Proc.Append("FROM comments as c ");
                    Proc.Append("WHERE parentid IS NULL and (archived = 0 or archived is null) ");
                    Proc.Append("and itemid = @itemid ");
                    Proc.Append("ORDER BY createdate ");
                }

                if(Provider == DBUtility.Providers.MySQL)
                {
                    Proc.Append("SELECT id, parentid, userid, comments, createdate, subject, ");
                    Proc.Append("fn_comment_child_count(id) as childnodecount ");
                    Proc.Append("FROM comments ");
                    Proc.Append("WHERE parentid IS NULL and (archived = 0 or archived is null) ");
                    Proc.Append("and itemid = @itemid ");
                    Proc.Append("ORDER BY createdate ");
                }

                return FormatSQLStateMents(Proc);
            }
        }

        #endregion

        #region "MSSQL/MySQL Controls Procedure Properties "

        public StringBuilder ListControlByID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT controlid, displayname, controlpath, controlname ");
                Proc.Append("FROM usercontrols ");
                Proc.Append("WHERE (controlid = @control) ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListControlByName
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT controlid, displayname, controlpath, controlname  ");
                Proc.Append("FROM usercontrols ");
                Proc.Append("WHERE (controlname = @control) ");

                return FormatSQLStateMents(Proc);
            }
        }

        #endregion

        #region "MSSQL/MySQL Editor Procedure Properties "

        public StringBuilder GetEditorScreenDetails
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                if(Provider == DBUtility.Providers.SqlServer)
                {
                    Proc.Append("DECLARE @CNT int, @templateid uniqueidentifier ");
                    Proc.Append(" ");
                    Proc.Append("SELECT @templateid = templateid ");
                    Proc.Append("FROM page ");
                    Proc.Append("WHERE pageid = @pageid ");
                    Proc.Append(" ");
                    Proc.Append("SELECT @CNT = COUNT(*)  ");
                    Proc.Append("FROM page_working_data  ");
                    Proc.Append("WHERE pageid = @pageid ");
                    Proc.Append(" ");
                    Proc.Append("IF @CNT = 0 ");
                    Proc.Append(" ");
                    Proc.Append("	SELECT	 ");
                    Proc.Append("		RTRIM(th.templatename) as templatename,  ");
                    Proc.Append("		th.numberofplaceholders,  ");
                    Proc.Append("		t.placeholdernumber,  ");
                    Proc.Append("		RTRIM(t.fieldname) as fieldname, ");
                    Proc.Append("		t.fieldtype, ");
                    Proc.Append("		t.fieldheight, ");
                    Proc.Append("		t.fieldwidth, ");
                    Proc.Append("		page.title, ");
                    Proc.Append("		awd.placeholderdata, ");
                    Proc.Append("		t.id as templatefieldid ");
                    Proc.Append("	FROM template_header as th ");
                    Proc.Append("		LEFT JOIN templates as t on t.templateid = th.templateid ");
                    Proc.Append("		LEFT JOIN page as page on page.templateid = t.templateid  ");
                    Proc.Append("		LEFT JOIN page_working_data as awd on awd.pageid = page.pageid ");
                    Proc.Append("	WHERE t.templateid = @templateid ");
                    Proc.Append("	and page.pageid = @pageid ");
                    Proc.Append("	ORDER BY t.placeholdernumber ");
                    Proc.Append(" ");
                    Proc.Append("ELSE ");
                    Proc.Append("BEGIN ");
                    Proc.Append(" ");
                    Proc.Append("	SELECT	 ");
                    Proc.Append("		RTRIM(th.templatename) as templatename,  ");
                    Proc.Append("		th.numberofplaceholders,  ");
                    Proc.Append("		t.placeholdernumber,  ");
                    Proc.Append("		RTRIM(t.fieldname) as fieldname, ");
                    Proc.Append("		t.fieldtype, ");
                    Proc.Append("		t.fieldheight, ");
                    Proc.Append("		t.fieldwidth, ");
                    Proc.Append("		page.title, ");
                    Proc.Append("		awd.placeholderdata, ");
                    Proc.Append("		t.id as templatefieldid ");
                    Proc.Append("	FROM template_header as th ");
                    Proc.Append("		LEFT JOIN templates as t on t.templateid = th.templateid ");
                    Proc.Append("		LEFT JOIN page as page on page.templateid = t.templateid  ");
                    Proc.Append("		LEFT JOIN page_working_data as awd on awd.pageid = page.pageid ");
                    Proc.Append("	WHERE t.templateid = @templateid ");
                    Proc.Append("	and page.pageid = @pageid ");
                    Proc.Append("	and awd.placeholdernumber = t.placeholdernumber ");
                    Proc.Append("	ORDER BY t.placeholdernumber ");
                    Proc.Append(" ");
                    Proc.Append("END ");
                }

                if(Provider == DBUtility.Providers.MySQL)
                {
                    Proc.Append("CALL usp_get_editorscreendetails(@pageid);");
                }

                return FormatSQLStateMents(Proc);
            }
        }

        #endregion

        #region "MSSQL/MySQL Event Procedure Properties "

        public StringBuilder GetEventByEventID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("EventID, ");
                Proc.Append("EventTitle, ");
                Proc.Append("EventDetails, ");
                Proc.Append("EventDate, ");
                Proc.Append("UserID, ");
                Proc.Append("StartDate, ");
                Proc.Append("EndDate, ");
                Proc.Append("Day, ");
                Proc.Append("Month, ");
                Proc.Append("Year, ");
                Proc.Append("Hr, ");
                Proc.Append("Min, ");
                Proc.Append("Meridian, ");
                Proc.Append("Occurenceid, ");
                Proc.Append("Private, ");
                Proc.Append("dbo.fn_comment_count(eventid) as comments, ");
                Proc.Append("dbo.fn_view_count(eventid) as views, ");
                Proc.Append("IsNull(dbo.fn_rank_count(eventid), 0) as rank ");
                Proc.Append("FROM events ");
                Proc.Append("WHERE EventID = @EventID ");

                return FormatSQLStateMents(Proc);

            }
        }

        public StringBuilder InsertEvent
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("INSERT INTO events ( ");
                Proc.Append("EventID, ");
                Proc.Append("EventTitle, ");
                Proc.Append("EventDetails, ");
                Proc.Append("EventDate, ");
                Proc.Append("UserID, ");
                Proc.Append("StartDate, ");
                Proc.Append("EndDate, ");
                Proc.Append("Day, ");
                Proc.Append("Month, ");
                Proc.Append("Year, ");
                Proc.Append("Hr, ");
                Proc.Append("Min, ");
                Proc.Append("Meridian, ");
                Proc.Append("Occurenceid, ");
                Proc.Append("Private ");
                Proc.Append(") VALUES ( ");
                Proc.Append("@EventID, ");
                Proc.Append("@EventTitle, ");
                Proc.Append("@EventDetails, ");
                Proc.Append("@EventDate, ");
                Proc.Append("@UserID, ");
                Proc.Append("@StartDate, ");
                Proc.Append("@EndDate, ");
                Proc.Append("@Day, ");
                Proc.Append("@Month, ");
                Proc.Append("@Year, ");
                Proc.Append("@Hr, ");
                Proc.Append("@Min, ");
                Proc.Append("@Meridian, ");
                Proc.Append("@Occurenceid, ");
                Proc.Append("@Private ");
                Proc.Append(") ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder UpdateEvent
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("UPDATE events SET ");
                Proc.Append("EventTitle = @EventTitle, ");
                Proc.Append("EventDetails = @EventDetails, ");
                Proc.Append("EventDate = @EventDate, ");
                Proc.Append("StartDate = @StartDate, ");
                Proc.Append("EndDate = @EndDate, ");
                Proc.Append("Day = @Day, ");
                Proc.Append("Month = @Month, ");
                Proc.Append("Year = @Year, ");
                Proc.Append("Hr = @Hr, ");
                Proc.Append("Min = @Min, ");
                Proc.Append("Meridian = @Meridian, ");
                Proc.Append("Occurenceid = @Occurenceid, ");
                Proc.Append("Private = @Private ");
                Proc.Append("WHERE EventID = @EventID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder UpdateEventByOccurenceID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("UPDATE events SET ");
                Proc.Append("EventTitle = @EventTitle, ");
                Proc.Append("EventDetails = @EventDetails, ");
                Proc.Append("StartDate = @StartDate, ");
                Proc.Append("EndDate = @EndDate, ");
                Proc.Append("Day = @Day, ");
                Proc.Append("Month = @Month, ");
                Proc.Append("Year = @Year, ");
                Proc.Append("Hr = @Hr, ");
                Proc.Append("Min = @Min, ");
                Proc.Append("Meridian = @Meridian, ");
                Proc.Append("Private = @Private ");
                Proc.Append("WHERE Occurenceid = @Occurenceid ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder DeleteEvent
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("DELETE FROM events WHERE EventID = @EventID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListEvents
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("EventID, ");
                Proc.Append("EventTitle, ");
                Proc.Append("EventDetails, ");
                Proc.Append("EventDate, ");
                Proc.Append("UserID, ");
                Proc.Append("dbo.fn_comment_count(EventID) as comments, ");
                Proc.Append("dbo.fn_view_count(EventID) as views, ");
                Proc.Append("IsNull(dbo.fn_rank_count(EventID), 0) as rank ");
                Proc.Append("FROM events ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListEventsByUser
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("EventID, ");
                Proc.Append("EventTitle, ");
                Proc.Append("EventDetails, ");
                Proc.Append("EventDate, ");
                Proc.Append("UserID, ");
                Proc.Append("dbo.fn_comment_count(EventID) as comments, ");
                Proc.Append("dbo.fn_view_count(EventID) as views, ");
                Proc.Append("IsNull(dbo.fn_rank_count(EventID), 0) as rank ");
                Proc.Append("FROM events ");
                Proc.Append("WHERE userid = @userid ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListEventsByDate
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("EventID, ");
                Proc.Append("EventTitle, ");
                Proc.Append("EventDetails, ");
                Proc.Append("EventDate, ");
                Proc.Append("UserID, ");
                Proc.Append("dbo.fn_comment_count(EventID) as comments, ");
                Proc.Append("dbo.fn_view_count(EventID) as views, ");
                Proc.Append("IsNull(dbo.fn_rank_count(EventID), 0) as rank ");
                Proc.Append("FROM events ");
                Proc.Append("WHERE EventDate = @date ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListEventsByMonthYear
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                if(Provider == DBUtility.Providers.SqlServer)
                {
                    Proc.Append("SELECT ");
                    Proc.Append("	EventID, ");
                    Proc.Append("	EventTitle, ");
                    Proc.Append("	EventDetails, ");
                    Proc.Append("	EventDate, ");
                    Proc.Append("	UserID, ");
                    Proc.Append("	dbo.fn_comment_count(EventID) as comments, ");
                    Proc.Append("	dbo.fn_view_count(EventID) as views, ");
                    Proc.Append("	IsNull(dbo.fn_rank_count(EventID), 0) as rank ");
                    Proc.Append("FROM events ");
                    Proc.Append("WHERE datepart(m, EventDate) = @month  ");
                    Proc.Append("and datepart(yyyy, EventDate) = @year ");
                }

                if(Provider == DBUtility.Providers.MySQL)
                {
                    Proc.Append("SELECT ");
                    Proc.Append("	EventID, ");
                    Proc.Append("	EventTitle, ");
                    Proc.Append("	EventDetails, ");
                    Proc.Append("	EventDate, ");
                    Proc.Append("	UserID, ");
                    Proc.Append("	dbo.fn_comment_count(EventID) as comments, ");
                    Proc.Append("	dbo.fn_view_count(EventID) as views, ");
                    Proc.Append("	IsNull(dbo.fn_rank_count(EventID), 0) as rank ");
                    Proc.Append("FROM events ");
                    Proc.Append("WHERE MONTH(EventDate) = @month  ");
                    Proc.Append("and YEAR(EventDate) = @year ");
                }

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListEventsByUserMonthYear
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                if(Provider == DBUtility.Providers.SqlServer)
                {
                    Proc.Append("SELECT ");
                    Proc.Append("	EventID, ");
                    Proc.Append("	EventTitle, ");
                    Proc.Append("	EventDetails, ");
                    Proc.Append("	EventDate, ");
                    Proc.Append("	UserID, ");
                    Proc.Append("	dbo.fn_comment_count(EventID) as comments, ");
                    Proc.Append("	dbo.fn_view_count(EventID) as views, ");
                    Proc.Append("	IsNull(dbo.fn_rank_count(EventID), 0) as rank ");
                    Proc.Append("FROM events ");
                    Proc.Append("WHERE userid = @userid  ");
                    Proc.Append("and datepart(m, EventDate) = @month  ");
                    Proc.Append("and datepart(yyyy, EventDate) = @year ");
                }

                if(Provider == DBUtility.Providers.MySQL)
                {
                    Proc.Append("SELECT ");
                    Proc.Append("EventID, ");
                    Proc.Append("EventTitle, ");
                    Proc.Append("EventDetails, ");
                    Proc.Append("EventDate, ");
                    Proc.Append("UserID, ");
                    Proc.Append("dbo.fn_comment_count(EventID) as comments, ");
                    Proc.Append("dbo.fn_view_count(EventID) as views, ");
                    Proc.Append("IsNull(dbo.fn_rank_count(EventID), 0) as rank ");
                    Proc.Append("FROM events ");
                    Proc.Append("WHERE userid = @userid  ");
                    Proc.Append("and MONTH(EventDate) = @month  ");
                    Proc.Append("and YEAR(EventDate) = @year ");
                }

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListEventsByOccurenceID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("EventID, ");
                Proc.Append("EventTitle, ");
                Proc.Append("EventDetails, ");
                Proc.Append("EventDate, ");
                Proc.Append("UserID ");
                Proc.Append("FROM events ");
                Proc.Append("WHERE Occurenceid = @Occurenceid ");

                return FormatSQLStateMents(Proc);
            }
        }

        #endregion

        #region "MSSQL/MySQL Forum Board Procedure Properties "

        public StringBuilder GetBoardByBoardID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("BoardID, ");
                Proc.Append("BoardName, ");
                Proc.Append("SortOrder, ");
                Proc.Append("LastUserID, ");
                Proc.Append("LastPostDate ");
                Proc.Append("FROM forum_board ");
                Proc.Append("WHERE BoardID = @BoardID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder InsertBoard
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("INSERT INTO forum_board ( ");
                Proc.Append("BoardID, ");
                Proc.Append("BoardName, ");
                Proc.Append("SortOrder, ");
                Proc.Append("LastPostDate, ");
                Proc.Append("LastUserID ");
                Proc.Append(") VALUES ( ");
                Proc.Append("@BoardID, ");
                Proc.Append("@BoardName, ");
                Proc.Append("@SortOrder, ");
                Proc.Append("CURRENT_TIMESTAMP, ");
                Proc.Append("@LastUserID ");
                Proc.Append(") ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder UpdateBoard
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("UPDATE forum_board SET ");
                Proc.Append("BoardName = @BoardName, ");
                Proc.Append("SortOrder = @SortOrder, ");
                Proc.Append("LastPostDate = CURRENT_TIMESTAMP, ");
                Proc.Append("LastUserID = @LastUserID ");
                Proc.Append("WHERE BoardID = @BoardID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder DeleteBoard
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                if(Provider == DBUtility.Providers.SqlServer)
                {
                    Proc.Append("DECLARE @cntpost int ");
                    Proc.Append(" ");
                    Proc.Append("SELECT  ");
                    Proc.Append("	@cntpost = COUNT(p.postid) ");
                    Proc.Append("FROM forum_post as p ");
                    Proc.Append("JOIN forum_topic as t on t.topicid = p.topicid ");
                    Proc.Append("JOIN forum_forum as f on f.forumid = t.forumid ");
                    Proc.Append("JOIN forum_category as c on c.categoryid = f.categoryid ");
                    Proc.Append("JOIN forum_board as b on b.boardid = c.boardid ");
                    Proc.Append("WHERE b.boardid = @BoardID ");
                    Proc.Append(" ");
                    Proc.Append("IF @cntpost > 0 ");
                    Proc.Append("BEGIN ");
                    Proc.Append(" ");
                    Proc.Append("	DECLARE @PostID uniqueidentifier ");
                    Proc.Append(" ");
                    Proc.Append("	SELECT @PostID = p.postid ");
                    Proc.Append("	FROM forum_post as p ");
                    Proc.Append("	JOIN forum_topic as t on t.topicid = p.topicid ");
                    Proc.Append("	JOIN forum_forum as f on f.forumid = t.forumid ");
                    Proc.Append("	JOIN forum_category as c on c.categoryid = f.categoryid ");
                    Proc.Append("	JOIN forum_board as b on b.boardid = c.boardid ");
                    Proc.Append("	WHERE b.boardid = @BoardID ");
                    Proc.Append(" ");
                    Proc.Append("	DELETE FROM forum_post WHERE PostID = @PostID ");
                    Proc.Append(" ");
                    Proc.Append("	DELETE FROM item_resources WHERE itemid = @PostID ");
                    Proc.Append("	DELETE FROM subscriptions WHERE itemid = @PostID ");
                    Proc.Append("	DELETE FROM views WHERE itemid = @PostID ");
                    Proc.Append("	DELETE FROM ranks WHERE itemid = @PostID ");
                    Proc.Append("	DELETE FROM tags WHERE itemid = @PostID ");
                    Proc.Append("	DELETE FROM comments WHERE itemid = @PostID ");
                    Proc.Append("	DELETE FROM Options WHERE itemid = @PostID ");
                    Proc.Append("	DELETE FROM security WHERE secureitemid = @PostID ");
                    Proc.Append(" ");
                    Proc.Append("END ");
                    Proc.Append(" ");
                    Proc.Append("DECLARE @cnttopic int ");
                    Proc.Append(" ");
                    Proc.Append("SELECT  ");
                    Proc.Append("	@cnttopic = COUNT(t.topicid) ");
                    Proc.Append("FROM forum_topic as t ");
                    Proc.Append("JOIN forum_forum as f on f.forumid = t.forumid ");
                    Proc.Append("JOIN forum_category as c on c.categoryid = f.categoryid ");
                    Proc.Append("JOIN forum_board as b on b.boardid = c.boardid ");
                    Proc.Append("WHERE b.boardid = @BoardID ");
                    Proc.Append(" ");
                    Proc.Append("IF @cnttopic > 0 ");
                    Proc.Append("BEGIN ");
                    Proc.Append(" ");
                    Proc.Append("	DECLARE @TopicID uniqueidentifier ");
                    Proc.Append(" ");
                    Proc.Append("	SELECT @TopicID = t.topicid ");
                    Proc.Append("	FROM forum_topic as t ");
                    Proc.Append("	JOIN forum_forum as f on f.forumid = t.forumid ");
                    Proc.Append("	JOIN forum_category as c on c.categoryid = f.categoryid ");
                    Proc.Append("	JOIN forum_board as b on b.boardid = c.boardid ");
                    Proc.Append("	WHERE b.boardid = @BoardID ");
                    Proc.Append(" ");
                    Proc.Append("	DELETE FROM forum_topic WHERE TopicID = @TopicID ");
                    Proc.Append(" ");
                    Proc.Append("END ");
                    Proc.Append(" ");
                    Proc.Append("DECLARE @cntforum int ");
                    Proc.Append(" ");
                    Proc.Append("SELECT  ");
                    Proc.Append("	@cntforum = COUNT(f.forumid) ");
                    Proc.Append("FROM forum_forum as f ");
                    Proc.Append("JOIN forum_category as c on c.categoryid = f.categoryid ");
                    Proc.Append("JOIN forum_board as b on b.boardid = c.boardid ");
                    Proc.Append("WHERE b.boardid = @BoardID ");
                    Proc.Append(" ");
                    Proc.Append("IF @cntforum > 0 ");
                    Proc.Append("BEGIN ");
                    Proc.Append(" ");
                    Proc.Append("	DECLARE @ForumID uniqueidentifier ");
                    Proc.Append(" ");
                    Proc.Append("	SELECT @ForumID = f.forumid ");
                    Proc.Append("	FROM forum_forum as f ");
                    Proc.Append("	JOIN forum_category as c on c.categoryid = f.categoryid ");
                    Proc.Append("	JOIN forum_board as b on b.boardid = c.boardid ");
                    Proc.Append("	WHERE b.boardid = @BoardID ");
                    Proc.Append(" ");
                    Proc.Append("	DELETE FROM forum_forum WHERE ForumID = @ForumID ");
                    Proc.Append(" ");
                    Proc.Append("END ");
                    Proc.Append(" ");
                    Proc.Append("DECLARE @cntcategory int ");
                    Proc.Append(" ");
                    Proc.Append("SELECT  ");
                    Proc.Append("	@cntcategory = COUNT(c.categoryid) ");
                    Proc.Append("FROM forum_category as c ");
                    Proc.Append("JOIN forum_board as b on b.boardid = c.boardid ");
                    Proc.Append("WHERE b.boardid = @BoardID ");
                    Proc.Append(" ");
                    Proc.Append("IF @cntcategory > 0 ");
                    Proc.Append("BEGIN ");
                    Proc.Append(" ");
                    Proc.Append("	DECLARE @CategoryID uniqueidentifier ");
                    Proc.Append(" ");
                    Proc.Append("	SELECT @CategoryID = c.categoryid ");
                    Proc.Append("	FROM forum_category as c ");
                    Proc.Append("	JOIN forum_board as b on b.boardid = c.boardid ");
                    Proc.Append("	WHERE b.boardid = @BoardID ");
                    Proc.Append(" ");
                    Proc.Append("	DELETE FROM forum_category WHERE CategoryID = @CategoryID ");
                    Proc.Append(" ");
                    Proc.Append("END ");
                    Proc.Append(" ");
                    Proc.Append("DELETE FROM forum_board WHERE BoardID = @BoardID ");
                }

                if(Provider == DBUtility.Providers.MySQL)
                {
                    Proc.Append("CALL usp_delete_board(@BoardID);");
                }

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListBoards
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                if(Provider == DBUtility.Providers.SqlServer)
                {
                    Proc.Append("IF @ListType = 0 ");
                    Proc.Append(" ");
                    Proc.Append("	SELECT DISTINCT ");
                    Proc.Append("		b.BoardID, ");
                    Proc.Append("		b.BoardName, ");
                    Proc.Append("		b.SortOrder, ");
                    Proc.Append("		b.lastuserid, ");
                    Proc.Append("		b.LastPostDate, ");
                    Proc.Append("		dbo.fn_post_get_categoryid_byboard(b.boardid) as categoryid ");
                    Proc.Append("	FROM ");
                    Proc.Append("		forum_board as b ");
                    Proc.Append(" ");
                    Proc.Append("ELSE ");
                    Proc.Append("BEGIN ");
                    Proc.Append(" ");
                    Proc.Append("	SELECT DISTINCT ");
                    Proc.Append("		b.BoardID, ");
                    Proc.Append("		b.BoardName, ");
                    Proc.Append("		b.SortOrder, ");
                    Proc.Append("		b.lastuserid, ");
                    Proc.Append("		b.LastPostDate, ");
                    Proc.Append("		dbo.fn_post_get_categoryid_byboard(b.boardid) as categoryid ");
                    Proc.Append("	FROM ");
                    Proc.Append("		forum_board as b ");
                    Proc.Append("	left join forum_category as c on c.boardid = b.boardid ");
                    Proc.Append("	WHERE c.categoryid Is Not Null ");
                    Proc.Append(" ");
                    Proc.Append("END ");
                }

                if(Provider == DBUtility.Providers.MySQL)
                {
                    Proc.Append("CALL usp_list_boards_bytype(@ListType);");
                }

                return FormatSQLStateMents(Proc);

            }
        }

        public StringBuilder ForumBoardSelectionList
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("BoardID, ");
                Proc.Append("BoardName ");
                Proc.Append("FROM forum_board ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListLinkDataForBoardByBoardID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT DISTINCT ");
                Proc.Append("b.BoardID, ");
                Proc.Append("b.boardname, ");
                Proc.Append("c.categoryid, ");
                Proc.Append("c.categoryname ");
                Proc.Append("FROM forum_category as c ");
                Proc.Append("JOIN forum_board as b on b.boardid = c.boardid ");
                Proc.Append("WHERE b.boardid = @boardid ");

                return FormatSQLStateMents(Proc);
            }
        }

        #endregion

        #region "MSSQL/MySQL Forum Category Procedure Properties "

        public StringBuilder GetCategoryByCategoryID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("CategoryID, ");
                Proc.Append("BoardID, ");
                Proc.Append("CategoryName, ");
                Proc.Append("SortOrder, ");
                Proc.Append("LastUserID, ");
                Proc.Append("LastPostDate ");
                Proc.Append("FROM forum_category ");
                Proc.Append("WHERE CategoryID = @CategoryID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder InsertForumCategory
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("INSERT INTO forum_category ( ");
                Proc.Append("CategoryID, ");
                Proc.Append("BoardID, ");
                Proc.Append("CategoryName, ");
                Proc.Append("SortOrder, ");
                Proc.Append("LastPostDate, ");
                Proc.Append("LastUserID ");
                Proc.Append(") VALUES ( ");
                Proc.Append("@CategoryID, ");
                Proc.Append("@BoardID, ");
                Proc.Append("@CategoryName, ");
                Proc.Append("@SortOrder, ");
                Proc.Append("CURRENT_TIMESTAMP, ");
                Proc.Append("@LastUserID ");
                Proc.Append(") ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder UpdateForumCategory
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("UPDATE forum_category SET ");
                Proc.Append("BoardID = @BoardID, ");
                Proc.Append("CategoryName = @CategoryName, ");
                Proc.Append("SortOrder = @SortOrder, ");
                Proc.Append("LastPostDate = CURRENT_TIMESTAMP, ");
                Proc.Append("LastUserID = @LastUserID ");
                Proc.Append("WHERE CategoryID = @CategoryID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder DeleteForumCategory
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                if(Provider == DBUtility.Providers.SqlServer)
                {
                    Proc.Append("DECLARE @cntpost int ");
                    Proc.Append("  ");
                    Proc.Append("SELECT ");
                    Proc.Append("	@cntpost = COUNT(p.postid) ");
                    Proc.Append("FROM forum_post as p ");
                    Proc.Append("JOIN forum_topic as t on t.topicid = p.topicid ");
                    Proc.Append("JOIN forum_forum as f on f.forumid = t.forumid ");
                    Proc.Append("JOIN forum_category as c on c.categoryid = f.categoryid ");
                    Proc.Append("WHERE c.categoryid = @CategoryID ");
                    Proc.Append(" ");
                    Proc.Append("IF @cntpost > 0 ");
                    Proc.Append("BEGIN ");
                    Proc.Append(" ");
                    Proc.Append("	DECLARE @PostID uniqueidentifier ");
                    Proc.Append(" ");
                    Proc.Append("	SELECT @PostID = p.postid ");
                    Proc.Append("	FROM forum_post as p ");
                    Proc.Append("	JOIN forum_topic as t on t.topicid = p.topicid ");
                    Proc.Append("	JOIN forum_forum as f on f.forumid = t.forumid ");
                    Proc.Append("	JOIN forum_category as c on c.categoryid = f.categoryid ");
                    Proc.Append("	WHERE c.categoryid = @CategoryID ");
                    Proc.Append(" ");
                    Proc.Append("	DELETE FROM forum_post WHERE PostID = @PostID ");
                    Proc.Append(" ");
                    Proc.Append("	DELETE FROM item_resources WHERE itemid = @PostID ");
                    Proc.Append("	DELETE FROM subscriptions WHERE itemid = @PostID ");
                    Proc.Append("	DELETE FROM views WHERE itemid = @PostID ");
                    Proc.Append("	DELETE FROM ranks WHERE itemid = @PostID ");
                    Proc.Append("	DELETE FROM tags WHERE itemid = @PostID ");
                    Proc.Append("	DELETE FROM comments WHERE itemid = @PostID ");
                    Proc.Append("	DELETE FROM Options WHERE itemid = @PostID ");
                    Proc.Append("	DELETE FROM security WHERE secureitemid = @PostID ");
                    Proc.Append(" ");
                    Proc.Append("END ");
                    Proc.Append(" ");
                    Proc.Append("DECLARE @cnttopic int ");
                    Proc.Append(" ");
                    Proc.Append("SELECT  ");
                    Proc.Append("	@cnttopic = COUNT(t.topicid) ");
                    Proc.Append("FROM forum_topic as t ");
                    Proc.Append("JOIN forum_forum as f on f.forumid = t.forumid ");
                    Proc.Append("JOIN forum_category as c on c.categoryid = f.categoryid ");
                    Proc.Append("WHERE c.categoryid = @CategoryID ");
                    Proc.Append(" ");
                    Proc.Append("IF @cnttopic > 0 ");
                    Proc.Append("BEGIN ");
                    Proc.Append(" ");
                    Proc.Append("	DECLARE @TopicID uniqueidentifier ");
                    Proc.Append(" ");
                    Proc.Append("	SELECT @TopicID = t.topicid ");
                    Proc.Append("	FROM forum_topic as t ");
                    Proc.Append("	JOIN forum_forum as f on f.forumid = t.forumid ");
                    Proc.Append("	JOIN forum_category as c on c.categoryid = f.categoryid ");
                    Proc.Append("	WHERE c.categoryid = @CategoryID ");
                    Proc.Append(" ");
                    Proc.Append("	DELETE FROM forum_topic WHERE TopicID = @TopicID ");
                    Proc.Append(" ");
                    Proc.Append("END ");
                    Proc.Append(" ");
                    Proc.Append("DECLARE @cntforum int ");
                    Proc.Append(" ");
                    Proc.Append("SELECT  ");
                    Proc.Append("	@cntforum = COUNT(f.forumid) ");
                    Proc.Append("FROM forum_forum as f ");
                    Proc.Append("JOIN forum_category as c on c.categoryid = f.categoryid ");
                    Proc.Append("WHERE c.categoryid = @CategoryID ");
                    Proc.Append(" ");
                    Proc.Append(" ");
                    Proc.Append("IF @cntforum > 0 ");
                    Proc.Append("BEGIN ");
                    Proc.Append(" ");
                    Proc.Append("	DECLARE @ForumID uniqueidentifier ");
                    Proc.Append(" ");
                    Proc.Append("	SELECT @ForumID = f.forumid ");
                    Proc.Append("	FROM forum_forum as f ");
                    Proc.Append("	JOIN forum_category as c on c.categoryid = f.categoryid ");
                    Proc.Append("	WHERE c.categoryid = @CategoryID ");
                    Proc.Append("	 ");
                    Proc.Append("	DELETE FROM forum_forum WHERE ForumID = @ForumID ");
                    Proc.Append(" ");
                    Proc.Append("END ");
                    Proc.Append(" ");
                    Proc.Append("DELETE FROM forum_category WHERE CategoryID = @CategoryID ");
                }

                if(Provider == DBUtility.Providers.MySQL)
                {
                    Proc.Append("CALL usp_delete_category(@CategoryID);");
                }

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListForumCategory
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("c.CategoryID, ");
                Proc.Append("c.BoardID, ");
                Proc.Append("c.CategoryName, ");
                Proc.Append("c.SortOrder, ");
                Proc.Append("b.boardname ");
                Proc.Append("FROM forum_category as c ");
                Proc.Append("LEFT JOIN forum_board as b on b.boardid = c.boardid ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListForumCategoryByCategoryID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT DISTINCT ");
                Proc.Append("CategoryID, ");
                Proc.Append("BoardID, ");
                Proc.Append("CategoryName, ");
                Proc.Append("SortOrder, ");
                Proc.Append("dbo.fn_topic_count_bycategory(CategoryID) as topiccount, ");
                Proc.Append("dbo.fn_post_count_bycategory(CategoryID) as postcount, ");
                Proc.Append("LastUserID, ");
                Proc.Append("LastPostDate ");
                Proc.Append("FROM forum_category ");
                Proc.Append("WHERE CategoryID = @categoryid ");

                return FormatSQLStateMents(Proc);

            }
        }

        public StringBuilder ListForumCategoryByBoardID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT DISTINCT ");
                Proc.Append("CategoryID, ");
                Proc.Append("BoardID, ");
                Proc.Append("CategoryName, ");
                Proc.Append("SortOrder, ");
                Proc.Append("dbo.fn_topic_count_bycategory(CategoryID) as topiccount, ");
                Proc.Append("dbo.fn_post_count_bycategory(CategoryID) as postcount, ");
                Proc.Append("LastUserID, ");
                Proc.Append("LastPostDate ");
                Proc.Append("FROM forum_category ");
                Proc.Append("WHERE BoardID = @boardid ");

                return FormatSQLStateMents(Proc);

            }
        }

        public StringBuilder ListLinkDataForCategoryByCategoryID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT DISTINCT ");
                Proc.Append("b.BoardID, ");
                Proc.Append("b.boardname, ");
                Proc.Append("c.categoryid, ");
                Proc.Append("c.categoryname ");
                Proc.Append("FROM forum_category as c ");
                Proc.Append("JOIN forum_board as b on b.boardid = c.boardid ");
                Proc.Append("WHERE c.categoryid = @categoryid ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ForumCategorySelectionList
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("CategoryID, ");
                Proc.Append("CategoryName ");
                Proc.Append("FROM forum_category ");

                return FormatSQLStateMents(Proc);
            }
        }

        #endregion

        #region "MSSQL/MySQL Forum Forum Procedure Properties "

        public StringBuilder GetForumByForumID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("ForumID, ");
                Proc.Append("CategoryID, ");
                Proc.Append("ForumName, ");
                Proc.Append("Description, ");
                Proc.Append("SortOrder, ");
                Proc.Append("TopicsCount, ");
                Proc.Append("PostsCount, ");
                Proc.Append("LastPostBy, ");
                Proc.Append("LastUserID, ");
                Proc.Append("LastPostDate, ");
                Proc.Append("Locked, ");
                Proc.Append("Moderated ");
                Proc.Append("FROM forum_forum ");
                Proc.Append("WHERE ForumID = @ForumID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder GetForumLockedByTopicID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("CASE WHEN forum_forum.locked = '' THEN 0 ELSE forum_forum.locked END AS locked ");
                Proc.Append("FROM forum_topic ");
                Proc.Append("JOIN forum_forum on forum_forum.forumid = forum_topic.forumid ");
                Proc.Append("WHERE forum_topic.topicid = @TopicID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder GetForumSecuredByTopicID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("select ISNull(count(*), 0) as secured ");
                Proc.Append("from forum_topic ");
                Proc.Append("join forum_forum on forum_forum.forumid = forum_topic.forumid ");
                Proc.Append("join security on security.secureitemid = forum_forum.forumid ");
                Proc.Append("where forum_topic.topicid = @TopicID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder GetForumLockedByForumID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("CASE WHEN locked = '' THEN 0 ELSE locked END AS locked ");
                Proc.Append("FROM forum_forum ");
                Proc.Append("WHERE forumid = @ForumID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder GetForumSecuredByForumID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("select ISNull(count(*), 0) as secured ");
                Proc.Append("from forum_forum ");
                Proc.Append("join security on security.secureitemid = forum_forum.forumid ");
                Proc.Append("where forum_forum.forumid = @ForumID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder GetForumModeratedByTopicID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("CASE WHEN forum_forum.moderated = '' THEN 0 ELSE forum_forum.moderated END AS moderated ");
                Proc.Append("FROM forum_topic ");
                Proc.Append("JOIN forum_forum on forum_forum.forumid = forum_topic.forumid ");
                Proc.Append("WHERE forum_topic.topicid = @TopicID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder GetForumModeratedByForumID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("CASE WHEN moderated = '' THEN 0 ELSE moderated END AS moderated ");
                Proc.Append("FROM forum_forum ");
                Proc.Append("WHERE forumid = @ForumID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder InsertForum
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("INSERT INTO forum_forum ( ");
                Proc.Append("ForumID, ");
                Proc.Append("CategoryID, ");
                Proc.Append("ForumName, ");
                Proc.Append("Description, ");
                Proc.Append("SortOrder, ");
                Proc.Append("LastUserID, ");
                Proc.Append("LastPostDate, ");
                Proc.Append("Locked, ");
                Proc.Append("Moderated ");
                Proc.Append(") VALUES ( ");
                Proc.Append("@ForumID, ");
                Proc.Append("@CategoryID, ");
                Proc.Append("@ForumName, ");
                Proc.Append("@Description, ");
                Proc.Append("@SortOrder, ");
                Proc.Append("@LastUserID, ");
                Proc.Append("CURRENT_TIMESTAMP, ");
                Proc.Append("@Locked, ");
                Proc.Append("@Moderated ");
                Proc.Append(") ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder UpdateForum
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("UPDATE forum_forum SET ");
                Proc.Append("CategoryID = @CategoryID, ");
                Proc.Append("ForumName = @ForumName, ");
                Proc.Append("Description = @Description, ");
                Proc.Append("SortOrder = @SortOrder, ");
                Proc.Append("LastUserID = @LastUserID, ");
                Proc.Append("LastPostDate = CURRENT_TIMESTAMP, ");
                Proc.Append("Locked = @Locked, ");
                Proc.Append("Moderated = @Moderated ");
                Proc.Append("WHERE ForumID = @ForumID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder DeleteForum
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                if(Provider == DBUtility.Providers.SqlServer)
                {
                    Proc.Append("DECLARE @cntpost int ");
                    Proc.Append(" ");
                    Proc.Append("SELECT ");
                    Proc.Append("	@cntpost = COUNT(p.postid) ");
                    Proc.Append("FROM forum_post as p ");
                    Proc.Append("JOIN forum_topic as t on t.topicid = p.topicid ");
                    Proc.Append("JOIN forum_forum as f on f.forumid = t.forumid ");
                    Proc.Append("WHERE f.forumid = @ForumID ");
                    Proc.Append(" ");
                    Proc.Append("IF @cntpost > 0 ");
                    Proc.Append("BEGIN ");
                    Proc.Append(" ");
                    Proc.Append("	DECLARE @PostID uniqueidentifier ");
                    Proc.Append(" ");
                    Proc.Append("	SELECT @PostID = p.postid ");
                    Proc.Append("	FROM forum_post as p ");
                    Proc.Append("	JOIN forum_topic as t on t.topicid = p.topicid ");
                    Proc.Append("	JOIN forum_forum as f on f.forumid = t.forumid ");
                    Proc.Append("	WHERE f.forumid = @ForumID	 ");
                    Proc.Append("	 ");
                    Proc.Append("	DELETE FROM forum_post WHERE PostID = @PostID ");
                    Proc.Append(" ");
                    Proc.Append("	DELETE FROM item_resources WHERE itemid = @PostID ");
                    Proc.Append("	DELETE FROM subscriptions WHERE itemid = @PostID ");
                    Proc.Append("	DELETE FROM views WHERE itemid = @PostID ");
                    Proc.Append("	DELETE FROM ranks WHERE itemid = @PostID ");
                    Proc.Append("	DELETE FROM tags WHERE itemid = @PostID ");
                    Proc.Append("	DELETE FROM comments WHERE itemid = @PostID ");
                    Proc.Append("	DELETE FROM Options WHERE itemid = @PostID ");
                    Proc.Append("	DELETE FROM security WHERE secureitemid = @PostID ");
                    Proc.Append(" ");
                    Proc.Append("END ");
                    Proc.Append(" ");
                    Proc.Append("DECLARE @cnttopic int ");
                    Proc.Append(" ");
                    Proc.Append("SELECT  ");
                    Proc.Append("	@cnttopic = COUNT(t.topicid) ");
                    Proc.Append("FROM forum_topic as t ");
                    Proc.Append("JOIN forum_forum as f on f.forumid = t.forumid ");
                    Proc.Append("WHERE f.forumid = @ForumID ");
                    Proc.Append(" ");
                    Proc.Append("IF @cnttopic > 0 ");
                    Proc.Append("BEGIN ");
                    Proc.Append(" ");
                    Proc.Append("	DECLARE @TopicID uniqueidentifier ");
                    Proc.Append(" ");
                    Proc.Append("	SELECT @TopicID = t.topicid ");
                    Proc.Append("	FROM forum_topic as t ");
                    Proc.Append("	JOIN forum_forum as f on f.forumid = t.forumid ");
                    Proc.Append("	WHERE f.forumid = @ForumID ");
                    Proc.Append(" ");
                    Proc.Append("	DELETE FROM forum_topic WHERE TopicID = @TopicID ");
                    Proc.Append(" ");
                    Proc.Append("END ");
                    Proc.Append(" ");
                    Proc.Append("DELETE FROM forum_forum WHERE ForumID = @ForumID ");
                }

                if(Provider == DBUtility.Providers.MySQL)
                {
                    Proc.Append("CALL usp_delete_forum(@ForumID);");
                }

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListForumSelection
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("ForumID, ");
                Proc.Append("ForumName ");
                Proc.Append("FROM forum_forum ");

                return FormatSQLStateMents(Proc);

            }
        }

        public StringBuilder ListForumForum
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("f.ForumID, ");
                Proc.Append("f.CategoryID, ");
                Proc.Append("f.ForumName, ");
                Proc.Append("f.Description, ");
                Proc.Append("f.SortOrder, ");
                Proc.Append("f.TopicsCount, ");
                Proc.Append("f.PostsCount, ");
                Proc.Append("f.LastPostBy, ");
                Proc.Append("f.LastUserID, ");
                Proc.Append("f.LastPostDate, ");
                Proc.Append("c.categoryname, ");
                Proc.Append("b.boardname, ");
                Proc.Append("f.locked, ");
                Proc.Append("f.moderated ");
                Proc.Append("FROM forum_forum as f ");
                Proc.Append("LEFT JOIN forum_category as c on c.categoryid = f.categoryid ");
                Proc.Append("LEFT JOIN forum_board as b on b.boardid = c.boardid ");

                return FormatSQLStateMents(Proc);

            }
        }

        public StringBuilder ListForumForumByCategoryID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT DISTINCT ");
                Proc.Append("f.ForumID, ");
                Proc.Append("f.CategoryID, ");
                Proc.Append("f.ForumName, ");
                Proc.Append("f.Description, ");
                Proc.Append("f.SortOrder, ");
                Proc.Append("f.LastPostBy, ");
                Proc.Append("f.LastUserID, ");
                Proc.Append("f.LastPostDate, ");
                Proc.Append("c.BoardID, ");
                Proc.Append("b.boardname, ");
                Proc.Append("c.categoryname, ");
                Proc.Append("dbo.fn_topic_count_byforum(ForumID) as topiccount, ");
                Proc.Append("dbo.fn_post_count_byforum(ForumID) as postcount, ");
                Proc.Append("f.locked, ");
                Proc.Append("f.moderated ");
                Proc.Append("FROM forum_forum f ");
                Proc.Append("JOIN forum_category as c on c.categoryid = f.categoryid ");
                Proc.Append("JOIN forum_board as b on b.boardid = c.boardid ");
                Proc.Append("WHERE f.categoryid = @categoryid ");

                return FormatSQLStateMents(Proc);

            }
        }

        public StringBuilder ListLinkDataForForumByForumID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT DISTINCT ");
                Proc.Append("c.BoardID, ");
                Proc.Append("b.boardname, ");
                Proc.Append("c.categoryid, ");
                Proc.Append("c.categoryname, ");
                Proc.Append("f.forumid, ");
                Proc.Append("f.forumname ");
                Proc.Append("FROM forum_forum as f ");
                Proc.Append("JOIN forum_category as c on c.categoryid = f.categoryid ");
                Proc.Append("JOIN forum_board as b on b.boardid = c.boardid ");
                Proc.Append("WHERE f.forumid = @forumid ");

                return FormatSQLStateMents(Proc);
            }
        }

        #endregion

        #region "MSSQL/MySQL Forum Topic Procedure Properties "

        public StringBuilder GetTopicByTopicID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("TopicID, ");
                Proc.Append("ForumID, ");
                Proc.Append("TopicName, ");
                Proc.Append("UserID, ");
                Proc.Append("Created, ");
                Proc.Append("Views, ");
                Proc.Append("PostsCount, ");
                Proc.Append("LastPostBy, ");
                Proc.Append("LastUserID, ");
                Proc.Append("LastPostDate, ");
                Proc.Append("Sticky, ");
                Proc.Append("IsApproved ");
                Proc.Append("FROM forum_topic ");
                Proc.Append("WHERE TopicID = @TopicID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder InsertTopic
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("INSERT INTO forum_topic ( ");
                Proc.Append("TopicID, ");
                Proc.Append("ForumID, ");
                Proc.Append("TopicName, ");
                Proc.Append("UserID, ");
                Proc.Append("Created, ");
                Proc.Append("Views, ");
                Proc.Append("PostsCount, ");
                Proc.Append("LastPostBy, ");
                Proc.Append("LastUserID, ");
                Proc.Append("LastPostDate, ");
                Proc.Append("Sticky, ");
                Proc.Append("IsApproved ");
                Proc.Append(") VALUES ( ");
                Proc.Append("@TopicID, ");
                Proc.Append("@ForumID, ");
                Proc.Append("@TopicName, ");
                Proc.Append("@UserID, ");
                Proc.Append("@Created, ");
                Proc.Append("@Views, ");
                Proc.Append("@PostsCount, ");
                Proc.Append("@LastPostBy, ");
                Proc.Append("@LastUserID, ");
                Proc.Append("@LastPostDate, ");
                Proc.Append("@Sticky, ");
                Proc.Append("@IsApproved ");
                Proc.Append(") ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder UpdateTopic
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("UPDATE forum_topic SET ");
                Proc.Append("ForumID = @ForumID, ");
                Proc.Append("TopicName = @TopicName, ");
                Proc.Append("UserID = @UserID, ");
                Proc.Append("Created = @Created, ");
                Proc.Append("Views = @Views, ");
                Proc.Append("PostsCount = @PostsCount, ");
                Proc.Append("LastPostBy = @LastPostBy, ");
                Proc.Append("LastUserID = @LastUserID, ");
                Proc.Append("LastPostDate = @LastPostDate, ");
                Proc.Append("Sticky = @sticky, ");
                Proc.Append("IsApproved = @IsApproved ");
                Proc.Append("WHERE TopicID = @TopicID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder DeleteTopic
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("DELETE FROM forum_topic WHERE TopicID = @TopicID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder DeleteTopicPosts
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("DELETE FROM forum_post WHERE TopicID = @TopicID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListForumTopic
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("TopicID, ");
                Proc.Append("ForumID, ");
                Proc.Append("TopicName, ");
                Proc.Append("UserID, ");
                Proc.Append("Created, ");
                Proc.Append("dbo.fn_view_count(TopicID) as views, ");
                Proc.Append("PostsCount, ");
                Proc.Append("LastPostBy, ");
                Proc.Append("LastUserID, ");
                Proc.Append("LastPostDate ");
                Proc.Append("FROM forum_topic ");

                return FormatSQLStateMents(Proc);

            }
        }

        public StringBuilder ListForumTopicByForumID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("t.TopicID, ");
                Proc.Append("t.ForumID, ");
                Proc.Append("t.TopicName, ");
                Proc.Append("t.UserID, ");
                Proc.Append("t.Created, ");
                Proc.Append("dbo.fn_view_count(t.TopicID) as views, ");
                Proc.Append("t.LastPostBy, ");
                Proc.Append("t.LastUserID, ");
                Proc.Append("t.LastPostDate, ");
                Proc.Append("dbo.fn_post_count_bytopic(TopicID) as postcount, ");
                Proc.Append("f.forumname, ");
                Proc.Append("c.categoryid, ");
                Proc.Append("c.categoryname, ");
                Proc.Append("b.boardid, ");
                Proc.Append("b.boardname, ");
                Proc.Append("f.locked ");
                Proc.Append("FROM forum_topic t ");
                Proc.Append("JOIN forum_forum as f on f.ForumID = t.ForumID ");
                Proc.Append("JOIN forum_category as c on c.categoryid = f.categoryid ");
                Proc.Append("JOIN forum_board as b on b.boardid = c.boardid ");
                Proc.Append("WHERE t.ForumID = @forumid and t.IsApproved = 1 ");

                return FormatSQLStateMents(Proc);

            }
        }

		public StringBuilder ListActiveTopics
		{
			get
			{
				StringBuilder Proc = new StringBuilder();

				if (Provider == DBUtility.Providers.SqlServer)
				{
					Proc.Append("SELECT ");
					Proc.Append("Top 5");
					Proc.Append("t.TopicID, ");
					Proc.Append("t.ForumID, ");
					Proc.Append("t.TopicName, ");
					Proc.Append("t.UserID, ");
					Proc.Append("t.Created, ");
					Proc.Append("dbo.fn_view_count(t.TopicID) as views, ");
					Proc.Append("t.LastPostBy, ");
					Proc.Append("t.LastUserID, ");
					Proc.Append("t.LastPostDate, ");
					Proc.Append("dbo.fn_post_count_bytopic(TopicID) as postcount, ");
					Proc.Append("f.forumname, ");
					Proc.Append("c.categoryid, ");
					Proc.Append("c.categoryname, ");
					Proc.Append("b.boardid, ");
					Proc.Append("b.boardname, ");
					Proc.Append("f.locked ");
					Proc.Append("FROM forum_topic t ");
					Proc.Append("JOIN forum_forum as f on f.ForumID = t.ForumID ");
					Proc.Append("JOIN forum_category as c on c.categoryid = f.categoryid ");
					Proc.Append("JOIN forum_board as b on b.boardid = c.boardid ");
					Proc.Append("WHERE t.IsApproved = 1 ");
					Proc.Append("ORDER BY t.Created desc ");
				}

				if (Provider == DBUtility.Providers.MySQL)
				{
					Proc.Append("SELECT ");
					Proc.Append("forum_topic.TopicID, ");
					Proc.Append("forum_topic.ForumID, ");
					Proc.Append("forum_topic.TopicName, ");
					Proc.Append("forum_topic.UserID, ");
					Proc.Append("forum_topic.Created, ");
					Proc.Append("fn_view_count(forum_topic.TopicID) as views, ");
					Proc.Append("forum_topic.LastPostBy, ");
					Proc.Append("forum_topic.LastUserID, ");
					Proc.Append("forum_topic.LastPostDate, ");
					Proc.Append("fn_post_count_bytopic(forum_topic.TopicID) as postcount, ");
					Proc.Append("forum_forum.forumname, ");
					Proc.Append("forum_category.categoryid, ");
					Proc.Append("forum_category.categoryname, ");
					Proc.Append("forum_board.boardid, ");
					Proc.Append("forum_board.boardname, ");
					Proc.Append("forum_forum.locked ");
					Proc.Append("FROM forum_topic ");
					Proc.Append("JOIN forum_forum on forum_forum.ForumID = forum_topic.ForumID ");
					Proc.Append("JOIN forum_category on forum_category.categoryid = forum_forum.categoryid ");
					Proc.Append("JOIN forum_board on forum_board.boardid = forum_category.boardid ");
					Proc.Append("WHERE forum_topic.IsApproved = 1 ");
					Proc.Append("ORDER BY forum_topic.Created desc ");
					Proc.Append("LIMIT 5 ");
				}

				return FormatSQLStateMents(Proc);

			}
		}

        public StringBuilder ListLinkDataForTopicByTopicID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT DISTINCT ");
                Proc.Append("c.BoardID, ");
                Proc.Append("b.boardname, ");
                Proc.Append("c.categoryid, ");
                Proc.Append("c.categoryname, ");
                Proc.Append("f.forumid, ");
                Proc.Append("f.forumname, ");
                Proc.Append("t.topicid, ");
                Proc.Append("t.topicname ");
                Proc.Append("FROM forum_topic as t ");
                Proc.Append("JOIN forum_forum as f on f.forumid = t.forumid ");
                Proc.Append("JOIN forum_category as c on c.categoryid = f.categoryid ");
                Proc.Append("JOIN forum_board as b on b.boardid = c.boardid ");
                Proc.Append("WHERE t.topicid = @topicid ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListTopicEmailByTopicID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT DISTINCT ");
                Proc.Append("fp.userid, ");
                Proc.Append("vsi.title, ");
                Proc.Append("vsi.urlparams, "); 
                Proc.Append("vsi.linktype, ");
                Proc.Append("vsi.item ");
                Proc.Append("FROM forum_post as fp ");
                Proc.Append("JOIN vw_search_items as vsi on vsi.itemid = fp.topicid ");
                Proc.Append("WHERE vsi.itemid = @TopicID");

                return FormatSQLStateMents(Proc);
            }
        }

        #endregion

        #region "MSSQL/MySQL Forum Post Procedure Properties "

        public StringBuilder GetPostByPostID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("PostID, ");
                Proc.Append("TopicID, ");
                Proc.Append("RepliedTo, ");
                Proc.Append("UserID, ");
                Proc.Append("Created, ");
                Proc.Append("Post, ");
                Proc.Append("Edited, ");
                Proc.Append("IsApproved ");
                Proc.Append("FROM forum_post ");
                Proc.Append("WHERE PostID = @PostID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder UpdateForumLastUser
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                if(Provider == DBUtility.Providers.SqlServer)
                {
                    Proc.Append("DECLARE @ForumID uniqueidentifier ");
                    Proc.Append(" ");
                    Proc.Append("SELECT @ForumID=ForumID FROM forum_topic WHERE topicid = @TopicID; ");
                    Proc.Append(" ");
                    Proc.Append("UPDATE forum_forum SET ");
                    Proc.Append("LastUserID = @LastUserID, ");
                    Proc.Append("LastPostDate = @LastPostDate ");
                    Proc.Append("WHERE ForumID = @ForumID; ");
                }

                if(Provider == DBUtility.Providers.MySQL)
                {
                    Proc.Append("SET @ForumID=0; ");
                    Proc.Append(" ");
                    Proc.Append("SELECT @ForumID:= ForumID FROM forum_topic WHERE topicid = ?topicid; ");
                    Proc.Append(" ");
                    Proc.Append("UPDATE forum_forum SET ");
                    Proc.Append("LastUserID = ?LastUserID, ");
                    Proc.Append("LastPostDate = ?LastPostDate ");
                    Proc.Append("WHERE ForumID = @ForumID; ");
                }

                return Proc;
            }
        }

        public StringBuilder UpdateTopicLastUser
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("UPDATE forum_topic SET ");
                Proc.Append("LastUserID = @LastUserID, ");
                Proc.Append("LastPostDate = @LastPostDate ");
                Proc.Append("WHERE TopicID = @TopicID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder UpdateCategoryLastUser
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                if(Provider == DBUtility.Providers.SqlServer)
                {
                    Proc.Append("DECLARE @ForumID uniqueidentifier ");
                    Proc.Append("DECLARE @CategoryID uniqueidentifier ");
                    Proc.Append(" ");
                    Proc.Append("SELECT @ForumID=ForumID FROM forum_topic WHERE topicid = @TopicID ");
                    Proc.Append("SELECT @CategoryID=CategoryID FROM forum_forum WHERE forumid = @ForumID ");
                    Proc.Append(" ");
                    Proc.Append("UPDATE forum_category SET ");
                    Proc.Append("LastUserID = @LastUserID, ");
                    Proc.Append("LastPostDate = @LastPostDate ");
                    Proc.Append("WHERE CategoryID = @CategoryID ");
                }
                if(Provider == DBUtility.Providers.MySQL)
                {
                    Proc.Append("SET @ForumID = 0; ");
                    Proc.Append("SET @CategoryID = 0; ");
                    Proc.Append(" ");
                    Proc.Append("SELECT @ForumID:= ForumID FROM forum_topic WHERE topicid = ?topicid; ");
                    Proc.Append("SELECT @CategoryID:= CategoryID FROM forum_forum WHERE forumid = @ForumID; ");
                    Proc.Append(" ");
                    Proc.Append("UPDATE forum_category SET ");
                    Proc.Append("LastUserID = ?LastUserID, ");
                    Proc.Append("LastPostDate = ?LastPostDate ");
                    Proc.Append("WHERE CategoryID = @CategoryID; ");
                }

                return Proc;
            }
        }

        public StringBuilder UpdateBoardLastUser
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                if(Provider == DBUtility.Providers.SqlServer)
                {
                    Proc.Append("DECLARE @ForumID uniqueidentifier ");
                    Proc.Append("DECLARE @CategoryID uniqueidentifier ");
                    Proc.Append("DECLARE @BoardID uniqueidentifier ");
                    Proc.Append(" ");
                    Proc.Append("SELECT @ForumID=ForumID FROM forum_topic WHERE topicid = @TopicID ");
                    Proc.Append("SELECT @CategoryID=CategoryID FROM forum_forum WHERE  forumid = @ForumID ");
                    Proc.Append("SELECT @BoardID=BoardID FROM forum_category WHERE categoryid= @CategoryID ");
                    Proc.Append(" ");
                    Proc.Append("UPDATE forum_board SET ");
                    Proc.Append("LastUserID = @LastUserID, ");
                    Proc.Append("LastPostDate = @LastPostDate ");
                    Proc.Append("WHERE BoardID = @BoardID ");
                }

                if(Provider == DBUtility.Providers.MySQL)
                {
                    Proc.Append("SET @ForumID = 0; ");
                    Proc.Append("SET @CategoryID = 0; ");
                    Proc.Append("SET @BoardID = 0; ");
                    Proc.Append(" ");
                    Proc.Append("SELECT @ForumID:= ForumID FROM forum_topic WHERE topicid = ?topicid; ");
                    Proc.Append("SELECT @CategoryID:= CategoryID FROM forum_forum WHERE forumid = @ForumID; ");
                    Proc.Append("SELECT @BoardID:= BoardID FROM forum_category WHERE categoryid= @CategoryID; ");
                    Proc.Append(" ");
                    Proc.Append("UPDATE forum_board SET ");
                    Proc.Append("LastUserID = ?LastUserID, ");
                    Proc.Append("LastPostDate = ?LastPostDate ");
                    Proc.Append("WHERE BoardID = @BoardID; ");
                }

                return Proc;
            }
        }

        public StringBuilder InsertPost
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("INSERT INTO forum_post ( ");
                Proc.Append("PostID, ");
                Proc.Append("TopicID, ");
                Proc.Append("RepliedTo, ");
                Proc.Append("UserID, ");
                Proc.Append("Created, ");
                Proc.Append("Post, ");
                Proc.Append("Edited, ");
                Proc.Append("IsApproved ");
                Proc.Append(") VALUES ( ");
                Proc.Append("@PostID, ");
                Proc.Append("@TopicID, ");
                Proc.Append("@RepliedTo, ");
                Proc.Append("@UserID, ");
                Proc.Append("@Created, ");
                Proc.Append("@Post, ");
                Proc.Append("@Edited, ");
                Proc.Append("@IsApproved ");
                Proc.Append(") ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder UpdatePost
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("UPDATE forum_post SET ");
                Proc.Append("TopicID = @TopicID, ");
                Proc.Append("RepliedTo = @RepliedTo, ");
                Proc.Append("UserID = @UserID, ");
                Proc.Append("Created = @Created, ");
                Proc.Append("Post = @Post, ");
                Proc.Append("Edited = @Edited, ");
                Proc.Append("IsApproved = @IsApproved ");
                Proc.Append("WHERE PostID = @PostID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder DeletePost
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("DELETE FROM forum_post WHERE PostID = @PostID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListForumPost
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("PostID, ");
                Proc.Append("TopicID, ");
                Proc.Append("RepliedTo, ");
                Proc.Append("UserID, ");
                Proc.Append("Created, ");
                Proc.Append("Post, ");
                Proc.Append("Edited, ");
                Proc.Append("dbo.fn_post_count_byuser(userid) as userpostcount ");
                Proc.Append("FROM forum_post ");
                Proc.Append("WHERE IsApproved = 1 ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListForumPostByTopicID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT DISTINCT ");
                Proc.Append("p.PostID, ");
                Proc.Append("p.TopicID, ");
                Proc.Append("p.RepliedTo, ");
                Proc.Append("p.UserID, ");
                Proc.Append("p.Created, ");
                Proc.Append("p.Post, ");
                Proc.Append("p.Edited, ");
                Proc.Append("t.topicname, ");
                Proc.Append("f.forumname, ");
                Proc.Append("f.forumid, ");
                Proc.Append("c.categoryname, ");
                Proc.Append("c.categoryid, ");
                Proc.Append("b.boardname, ");
                Proc.Append("b.boardid, ");
                Proc.Append("f.locked, ");
                Proc.Append("dbo.fn_post_count_byuser(p.userid) as userpostcount ");
                Proc.Append("FROM forum_post p ");
                Proc.Append("JOIN forum_topic as t on t.topicid = p.topicid ");
                Proc.Append("JOIN forum_forum as f on f.ForumID = t.ForumID ");
                Proc.Append("JOIN forum_category as c on c.categoryid = f.categoryid ");
                Proc.Append("JOIN forum_board as b on b.boardid = c.boardid ");
                Proc.Append("WHERE p.TopicID = @topicid and p.IsApproved = 1 ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListPendingForumPostsByUserID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("forum_topic.forumid, ");
                Proc.Append("forum_topic.topicid, ");
                Proc.Append("forum_post.postid, ");
                Proc.Append("forum_topic.topicname, ");
                Proc.Append("forum_post.post, ");
                Proc.Append("forum_post.userid, ");
                Proc.Append("forum_post.created ");
                Proc.Append("FROM forum_topic ");
                Proc.Append("JOIN forum_post ON forum_post.topicid = forum_topic.topicid ");
                Proc.Append("WHERE forum_post.userid = @UserID ");
                Proc.Append("AND(forum_topic.isapproved = 0 OR forum_post.isapproved = 0) ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListPendingForumPostsByModeratorID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("DISTINCT ");
                Proc.Append("forum_topic.forumid, ");
                Proc.Append("forum_topic.topicid, ");
                Proc.Append("forum_post.postid, ");
                Proc.Append("forum_topic.topicname, ");
                Proc.Append("forum_post.post, ");
                Proc.Append("forum_post.userid, ");
                Proc.Append("forum_post.created ");
				Proc.Append("FROM forum_post ");
				Proc.Append("LEFT JOIN forum_topic ON forum_post.topicid = forum_topic.topicid ");
                Proc.Append("LEFT JOIN forum_moderators ON forum_moderators.forumid = forum_topic.forumid ");
                Proc.Append("WHERE (forum_moderators.userid = @ModeratorID ");
                Proc.Append("AND (forum_topic.isapproved = 0 OR forum_post.isapproved = 0)) ");
                Proc.Append("OR (forum_topic.isapproved = 0 OR forum_post.isapproved = 0) ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListPendingForumPostsCountByModeratorID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT count(distinct forum_post.postid) as pendingpostscount ");
                Proc.Append("FROM forum_topic ");
                Proc.Append("LEFT JOIN forum_post ON forum_post.topicid = forum_topic.topicid ");
                Proc.Append("LEFT JOIN forum_moderators ON forum_moderators.forumid = forum_topic.forumid ");
                Proc.Append("WHERE (forum_moderators.userid = @ModeratorID ");
                Proc.Append("AND(forum_topic.isapproved = 0 OR forum_post.isapproved = 0)) ");
                Proc.Append("OR (forum_topic.isapproved = 0 OR forum_post.isapproved = 0) ");

                return FormatSQLStateMents(Proc);
            }
        }

        #endregion

        #region "MSSQL/MySQL Forum Moderators Procedure Properties "

        public StringBuilder GetForumModeratorsByForumID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("UserID ");
                Proc.Append("FROM forum_moderators ");
                Proc.Append("WHERE ForumID = @ForumID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder InsertForumModerators
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("INSERT INTO forum_moderators ( ");
                Proc.Append("ForumID, ");
                Proc.Append("UserID ");
                Proc.Append(") VALUES ( ");
                Proc.Append("@ForumID, ");
                Proc.Append("@UserID ");
                Proc.Append(") ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder UpdateForumModerators
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("UPDATE forum_moderators SET ");
                Proc.Append("UserID = @UserID ");
                Proc.Append("WHERE ForumID = @ForumID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder DeleteForumModerators
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("DELETE FROM forum_moderators ");
                Proc.Append("WHERE ForumID = @ForumID ");
                Proc.Append("AND UserID = @UserID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder DeleteForumModeratorsByForumID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("DELETE FROM forum_moderators ");
                Proc.Append("WHERE ForumID = @ForumID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder DeleteForumModeratorsByBoardID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                if(Provider == DBUtility.Providers.SqlServer)
                {
                    Proc.Append("delete from forum_moderators ");
                    Proc.Append("from forum_moderators ");
                    Proc.Append("join forum_forum on forum_moderators.forumid = forum_forum.forumid ");
                    Proc.Append("join forum_category on forum_category.categoryid = forum_forum.categoryid ");
                    Proc.Append("join forum_board on forum_board.boardid = forum_category.boardid ");
                    Proc.Append("where forum_board.boardid = @BoardID ");
                }

                if(Provider == DBUtility.Providers.MySQL)
                {
                    Proc.Append("delete from forum_moderators ");
                    Proc.Append("using forum_moderators ");
                    Proc.Append("join forum_forum on forum_moderators.forumid = forum_forum.forumid ");
                    Proc.Append("join forum_category on forum_category.categoryid = forum_forum.categoryid ");
                    Proc.Append("join forum_board on forum_board.boardid = forum_category.boardid ");
                    Proc.Append("where forum_board.boardid = @BoardID ");
                }

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder DeleteForumModeratorsByCategoryID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                if(Provider == DBUtility.Providers.SqlServer)
                {
                    Proc.Append("delete from forum_moderators ");
                    Proc.Append("from forum_moderators ");
                    Proc.Append("join forum_forum on forum_moderators.forumid = forum_forum.forumid ");
                    Proc.Append("join forum_category on forum_category.categoryid = forum_forum.categoryid ");
                    Proc.Append("where forum_category.categoryid = @CategoryID ");
                }

                if(Provider == DBUtility.Providers.MySQL)
                {
                    Proc.Append("delete from forum_moderators ");
                    Proc.Append("using forum_moderators ");
                    Proc.Append("join forum_forum on forum_moderators.forumid = forum_forum.forumid ");
                    Proc.Append("join forum_category on forum_category.categoryid = forum_forum.categoryid ");
                    Proc.Append("where forum_category.categoryid = @CategoryID ");
                }

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListForumModeratorsByForumID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("userid ");
                Proc.Append("FROM forum_moderators ");
                Proc.Append("WHERE ForumID = @ForumID ");

                return FormatSQLStateMents(Proc);
            }
        }

        #endregion

        #region "MSSQL/MySQL Links Procedure Properties "

        public StringBuilder GetLinkByLinkID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("linkid, ");
                Proc.Append("linktitle, ");
                Proc.Append("linkurl, ");
                Proc.Append("linkdesc, ");
                Proc.Append("userid, ");
                Proc.Append("createdate ");
                Proc.Append("FROM links ");
                Proc.Append("WHERE linkid = @linkid ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder InsertLink
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("INSERT INTO links ( ");
                Proc.Append("linkid, ");
                Proc.Append("linktitle, ");
                Proc.Append("linkurl, ");
                Proc.Append("linkdesc, ");
                Proc.Append("userid, ");
                Proc.Append("createdate ");
                Proc.Append(") VALUES ( ");
                Proc.Append("@linkid, ");
                Proc.Append("@linktitle, ");
                Proc.Append("@linkurl, ");
                Proc.Append("@linkdesc, ");
                Proc.Append("@userid, ");
                Proc.Append("@createdate ");
                Proc.Append(") ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder UpdateLink
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("UPDATE links SET ");
                Proc.Append("linktitle = @linktitle, ");
                Proc.Append("linkurl = @linkurl, ");
                Proc.Append("linkdesc = @linkdesc, ");
                Proc.Append("userid = @userid, ");
                Proc.Append("createdate = @createdate ");
                Proc.Append("WHERE linkid = @linkid ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder DeleteLink
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("DELETE FROM links WHERE linkid = @linkid");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListLinks
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("linkid, ");
                Proc.Append("linktitle, ");
                Proc.Append("linkurl, ");
                Proc.Append("linkdesc, ");
                Proc.Append("userid, ");
                Proc.Append("createdate ");
                Proc.Append("FROM links ");

                return FormatSQLStateMents(Proc);
            }
        }

        #endregion

        #region "MSSQL/MySQL Menu Procedure Properties "

        public StringBuilder GetMenuByMenuID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("s.id, ");
                Proc.Append("s.title, ");
                Proc.Append("s.description, ");
                Proc.Append("s.url, ");
                Proc.Append("s.roles, ");
                Proc.Append("s.parent, ");
                Proc.Append("(SELECT count(*) FROM sitemap WHERE parent=s.id) as parentchildcount ");
                Proc.Append("FROM sitemap AS s ");
                Proc.Append("LEFT JOIN sitemap AS s1 ON s1.id = s.parent ");
                Proc.Append("WHERE s.id = @id ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder InsertMenu
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("INSERT INTO sitemap ");
                Proc.Append("( ");
                Proc.Append("title, ");
                Proc.Append("description, ");
                Proc.Append("url, ");
                Proc.Append("roles, ");
                Proc.Append("parent ");
                Proc.Append(")  ");
                Proc.Append("VALUES ");
                Proc.Append("( ");
                Proc.Append("@title, ");
                Proc.Append("@description, ");
                Proc.Append("@url, ");
                Proc.Append("@roles, ");
                Proc.Append("@parent ");
                Proc.Append(") ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder UpdateMenu
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                if(Provider == DBUtility.Providers.SqlServer)
                {
                    Proc.Append("IF @parent Is Null ");
                    Proc.Append("	UPDATE sitemap  ");
                    Proc.Append("	SET title = @title, ");
                    Proc.Append("	description = @description, ");
                    Proc.Append("	url = @url, ");
                    Proc.Append("	roles = @roles ");
                    Proc.Append("	WHERE id = @id ");
                    Proc.Append("ELSE ");
                    Proc.Append("BEGIN ");
                    Proc.Append("	UPDATE sitemap  ");
                    Proc.Append("	SET title = @title, ");
                    Proc.Append("	description = @description, ");
                    Proc.Append("	url = @url, ");
                    Proc.Append("	roles = @roles, ");
                    Proc.Append("	parent = @parent ");
                    Proc.Append("	WHERE id = @id ");
                    Proc.Append("END ");
                }

                if(Provider == DBUtility.Providers.MySQL)
                {
                    Proc.Append("CALL usp_insert_menu(@id, @title, @description, @url, @roles, @parent);");
                }

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder DeleteMenu
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("DELETE FROM sitemap WHERE id = @id");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListMenus
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("s.id, ");
                Proc.Append("s.title, ");
                Proc.Append("s.description, ");
                Proc.Append("s.url, ");
                Proc.Append("s.roles, ");
                Proc.Append("IsNull(s.parent, 0) as parent, ");
                Proc.Append("IsNull(s1.title, '') as parenttitle, ");
                Proc.Append("IsNull(s1.url, '') as parenturl, ");
                Proc.Append("(SELECT count(*) FROM sitemap WHERE parent=s.id) as parentchildcount ");
                Proc.Append("FROM sitemap AS s ");
                Proc.Append("LEFT JOIN sitemap AS s1 ON s1.id = s.parent ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListMenusByID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("id, ");
                Proc.Append("title, ");
                Proc.Append("description, ");
                Proc.Append("url, ");
                Proc.Append("roles, ");
                Proc.Append("parent ");
                Proc.Append("FROM sitemap ");
                Proc.Append("WHERE id = @id ");

                return FormatSQLStateMents(Proc);
            }
        }

        #endregion

        #region "MSSQL/MySQL Messaging Procedure Properties "

        public StringBuilder GetMessageByMessageID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("select privatemessageid, fromuserid, subject, body, createdate ");
                Proc.Append("from private_message ");
                Proc.Append("where privatemessageid = @privatemessageid; ");
                Proc.Append(" ");
                Proc.Append("update user_private_message set isviewed = 1 where privatemessageid = @privatemessageid; ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder InsertMessage
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("INSERT INTO private_message ");
                Proc.Append("( ");
                Proc.Append("PrivateMessageID, ");
                Proc.Append("FromUserID, ");
                Proc.Append("Subject, ");
                Proc.Append("Body ");
                Proc.Append(") ");
                Proc.Append("VALUES ");
                Proc.Append("( ");
                Proc.Append("@PrivateMessageID, ");
                Proc.Append("@FromUserID, ");
                Proc.Append("@Subject, ");
                Proc.Append("@Body ");
                Proc.Append("); ");
                Proc.Append(" ");
                Proc.Append("INSERT INTO user_private_message ");
                Proc.Append("( ");
                Proc.Append("UserPrivateMessageID, ");
                Proc.Append("UserID, ");
                Proc.Append("PrivateMessageID ");
                Proc.Append(") ");
                Proc.Append("VALUES ");
                Proc.Append("( ");
                Proc.Append("@UserPrivateMessageID, ");
                Proc.Append("@UserID, ");
                Proc.Append("@PrivateMessageID ");
                Proc.Append("); ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder UpdateMessage
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder DeleteMessage
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("delete from private_message where privatemessageid = @privatemessageid; ");
                Proc.Append("delete from user_private_message where privatemessageid = @privatemessageid; ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListPrivateMessageInboxItems
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("select pm.privatemessageid, pm.fromuserid, upm.userid, pm.subject, pm.createdate, upm.isviewed ");
                Proc.Append("from private_message as pm ");
                Proc.Append("left join user_private_message as upm on upm.privatemessageid = pm.privatemessageid ");
                Proc.Append("where upm.userid = @userid; ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListPrivateMessageCountByUserID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT dbo.fn_newmessage_count(@userid) as newmessages; ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListPrivateMessageSentItems
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("select pm.privatemessageid, pm.fromuserid, upm.userid, pm.subject, pm.createdate, upm.isviewed ");
                Proc.Append("from private_message as pm ");
                Proc.Append("left join user_private_message as upm on upm.privatemessageid = pm.privatemessageid ");
                Proc.Append("where fromuserid = @userid; ");

                return FormatSQLStateMents(Proc);
            }
        }

        #endregion

        #region "MSSQL/MySQL News Procedure Properties "

        public StringBuilder GetNewsByNewsID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("newsid,  ");
                Proc.Append("title,  ");
                Proc.Append("body,  ");
                Proc.Append("expiredate,  ");
                Proc.Append("sticky, ");
                Proc.Append("userid, ");
                Proc.Append("dbo.fn_comment_count(newsid) as comments, ");
                Proc.Append("dbo.fn_view_count(newsid) as views, ");
                Proc.Append("IsNull(dbo.fn_rank_count(newsid), 0) as rank ");
                Proc.Append("FROM news ");
                Proc.Append("WHERE newsid = @newsid ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder InsertNews
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("INSERT INTO news ");
                Proc.Append("( ");
                Proc.Append("newsid, ");
                Proc.Append("title, ");
                Proc.Append("body, ");
                Proc.Append("expiredate, ");
                Proc.Append("sticky, ");
                Proc.Append("userid ");
                Proc.Append(") ");
                Proc.Append("VALUES ");
                Proc.Append("( ");
                Proc.Append("@newsid, ");
                Proc.Append("@title, ");
                Proc.Append("@body, ");
                Proc.Append("@expiredate, ");
                Proc.Append("@sticky, ");
                Proc.Append("@userid ");
                Proc.Append("); ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder UpdateNews
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("UPDATE NEWS ");
                Proc.Append("SET body = @body, title = @title, expiredate = @expiredate, sticky = @sticky ");
                Proc.Append("WHERE newsid = @newsid; ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder DeleteNews
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("UPDATE news SET archived = 1 WHERE newsid = @newsid; ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListNews
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("newsid,  ");
                Proc.Append("title,  ");
                Proc.Append("body,  ");
                Proc.Append("createdate,  ");
                Proc.Append("expiredate,  ");
                Proc.Append("sticky,  ");
                Proc.Append("archived,  ");
                Proc.Append("dbo.fn_comment_count(newsid) as comments, ");
                Proc.Append("dbo.fn_view_count(newsid) as views, ");
                Proc.Append("IsNull(dbo.fn_rank_count(newsid), 0) as rank, ");
                Proc.Append("userid ");
                Proc.Append("FROM news ");
                Proc.Append("WHERE archived <> 1 and (expiredate >= CURRENT_TIMESTAMP or expiredate is null) ");
                Proc.Append("ORDER BY sticky DESC, createdate DESC; ");

                return FormatSQLStateMents(Proc);
            }
        }

		public StringBuilder ListNewsArchive
		{
			get
			{
				StringBuilder Proc = new StringBuilder();

				Proc.Append("SELECT ");
				Proc.Append("newsid,  ");
				Proc.Append("title,  ");
				Proc.Append("body,  ");
				Proc.Append("createdate,  ");
				Proc.Append("expiredate,  ");
				Proc.Append("sticky,  ");
				Proc.Append("archived,  ");
				Proc.Append("dbo.fn_comment_count(newsid) as comments, ");
				Proc.Append("dbo.fn_view_count(newsid) as views, ");
				Proc.Append("IsNull(dbo.fn_rank_count(newsid), 0) as rank, ");
				Proc.Append("userid ");
				Proc.Append("FROM news ");
				Proc.Append("WHERE archived = 1 or (expiredate <= CURRENT_TIMESTAMP or expiredate is null) ");
				Proc.Append("ORDER BY createdate DESC; ");

				return FormatSQLStateMents(Proc);
			}
		}

        #endregion

        #region "MSSQL/MySQL Nodes/Folders Procedure Properties "

        public StringBuilder GetFolderByFolderID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT nodeid, parentnodeid, name, userid ");
                Proc.Append("FROM folders ");
                Proc.Append("WHERE nodeid = @nodeid and (archived = 0 or archived is null) ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder InsertFolder
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("INSERT INTO folders ");
                Proc.Append("( ");
                Proc.Append("nodeid, ");
                Proc.Append("parentnodeid, ");
                Proc.Append("name, ");
                Proc.Append("userid ");
                Proc.Append(")  ");
                Proc.Append("VALUES ");
                Proc.Append("( ");
                Proc.Append("@nodeid, ");
                Proc.Append("@parentnodeid, ");
                Proc.Append("@name, ");
                Proc.Append("@userid ");
                Proc.Append(") ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder UpdateFolder
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                if(Provider == DBUtility.Providers.SqlServer)
                {
                    Proc.Append("IF @parentnodeid Is Null ");
                    Proc.Append("	UPDATE folders  ");
                    Proc.Append("	SET name = @name ");
                    Proc.Append("	WHERE nodeid = @nodeid ");
                    Proc.Append("ELSE ");
                    Proc.Append("BEGIN ");
                    Proc.Append("	UPDATE folders  ");
                    Proc.Append("	SET parentnodeid = @parentnodeid, name = @name ");
                    Proc.Append("	WHERE nodeid = @nodeid ");
                    Proc.Append("END ");
                }
                if(Provider == DBUtility.Providers.MySQL)
                {
                    Proc.Append("CALL usp_update_folder(@nodeid, @parentnodeid, @name);");
                }

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder DeleteFolder
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("UPDATE folders SET archived = @archived WHERE nodeid = @nodeid ");

                return FormatSQLStateMents(Proc);
            }
        }

        #endregion

        #region "MSSQL/MySQL NVLs Procedure Properties "

        public StringBuilder ListAccessType
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT int_value, RTRIM(longdesc) as longdesc, RTRIM(shortdesc) as shortdesc ");
                Proc.Append("FROM int_value ");
                Proc.Append("WHERE int_name = 'iv_access_type' ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListDifficultyLevel
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT int_value, RTRIM(longdesc) as longdesc, RTRIM(shortdesc) as shortdesc ");
                Proc.Append("FROM int_value ");
                Proc.Append("WHERE int_name = 'iv_level' ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListTemplate
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT templateid, RTRIM(templatename) as templatename, numberofplaceholders ");
                Proc.Append("FROM template_header ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListItemType
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT int_value, RTRIM(longdesc) as longdesc, RTRIM(shortdesc) as shortdesc ");
                Proc.Append("FROM int_value ");
                Proc.Append("WHERE int_name = 'iv_itemtype' ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListPriority
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT int_value, RTRIM(longdesc) as longdesc, RTRIM(shortdesc) as shortdesc ");
                Proc.Append("FROM int_value ");
                Proc.Append("WHERE int_name = 'iv_priority' ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListStatus
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT int_value, RTRIM(longdesc) as longdesc, RTRIM(shortdesc) as shortdesc ");
                Proc.Append("FROM int_value ");
                Proc.Append("WHERE int_name = 'iv_status' ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListFormType
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT int_value, RTRIM(longdesc) as longdesc, RTRIM(shortdesc) as shortdesc ");
                Proc.Append("FROM int_value ");
                Proc.Append("WHERE int_name = 'iv_formtype' ");

                return FormatSQLStateMents(Proc);
            }
        }

        #endregion

        #region "MSSQL/MySQL Options Procedure Properties "

        public StringBuilder GetOptionByItemID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("OptionsID, ");
                Proc.Append("ItemID, ");
                Proc.Append("AllowSummary, ");
                Proc.Append("AllowComments, ");
                Proc.Append("AllowTags, ");
                Proc.Append("AllowSubscriptions, ");
                Proc.Append("AllowRanking, ");
                Proc.Append("AllowInfoTools ");
                Proc.Append("FROM ");
                Proc.Append("Options ");
                Proc.Append("WHERE ItemID = @ItemID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder InsertOption
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("INSERT INTO Options ( ");
                Proc.Append("OptionsID, ");
                Proc.Append("ItemID, ");
                Proc.Append("AllowSummary, ");
                Proc.Append("AllowComments, ");
                Proc.Append("AllowTags, ");
                Proc.Append("AllowSubscriptions, ");
                Proc.Append("AllowRanking, ");
                Proc.Append("AllowInfoTools ");
                Proc.Append(") VALUES ( ");
                Proc.Append("@OptionsID, ");
                Proc.Append("@ItemID, ");
                Proc.Append("@AllowSummary, ");
                Proc.Append("@AllowComments, ");
                Proc.Append("@AllowTags, ");
                Proc.Append("@AllowSubscriptions, ");
                Proc.Append("@AllowRanking, ");
                Proc.Append("@AllowInfoTools ");
                Proc.Append(") ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder UpdateOption
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("UPDATE Options SET ");
                Proc.Append("ItemID = @ItemID, ");
                Proc.Append("AllowSummary = @AllowSummary, ");
                Proc.Append("AllowComments = @AllowComments, ");
                Proc.Append("AllowTags = @AllowTags, ");
                Proc.Append("AllowSubscriptions = @AllowSubscriptions, ");
                Proc.Append("AllowRanking = @AllowRanking, ");
                Proc.Append("AllowInfoTools = @AllowInfoTools ");
                Proc.Append("WHERE ItemID = @ItemID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder DeleteOption
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("DELETE FROM Options WHERE OptionsID = @OptionsID");

                return FormatSQLStateMents(Proc);
            }
        }

        #endregion

        #region "MSSQL/MySQL Page Procedure Properties "

        public StringBuilder GetPageArchiveDetails
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                if(Provider == DBUtility.Providers.SqlServer)
                {
                    Proc.Append("DECLARE @CNT int, @templateid uniqueidentifier ");
                    Proc.Append(" ");
                    Proc.Append("SELECT @templateid = templateid ");
                    Proc.Append("FROM page ");
                    Proc.Append("WHERE pageid = @pageid ");
                    Proc.Append(" ");
                    Proc.Append("SELECT @CNT = COUNT(*)  ");
                    Proc.Append("FROM page_archive_data  ");
                    Proc.Append("WHERE pageid = @pageid ");
                    Proc.Append(" ");
                    Proc.Append("IF @CNT = 0 ");
                    Proc.Append(" ");
                    Proc.Append("	SELECT	 ");
                    Proc.Append("		RTRIM(th.templatename) as templatename,  ");
                    Proc.Append("		th.numberofplaceholders,  ");
                    Proc.Append("		t.placeholdernumber,  ");
                    Proc.Append("		RTRIM(t.fieldname) as fieldname, ");
                    Proc.Append("		t.fieldtype, ");
                    Proc.Append("		t.fieldheight, ");
                    Proc.Append("		t.fieldwidth, ");
                    Proc.Append("		page.title, ");
                    Proc.Append("		pad.placeholderdata, ");
                    Proc.Append("		t.id as templatefieldid, ");
                    Proc.Append("		t.showname ");
                    Proc.Append("	FROM template_header as th ");
                    Proc.Append("		LEFT JOIN templates as t on t.templateid = th.templateid ");
                    Proc.Append("		LEFT JOIN page as page on page.templateid = t.templateid  ");
                    Proc.Append("		LEFT JOIN page_archive_data as pad on pad.pageid = page.pageid ");
                    Proc.Append("	WHERE t.templateid = @templateid ");
                    Proc.Append("	and page.pageid = @pageid ");
                    Proc.Append("	and pad.pagerevision = @revision ");
                    Proc.Append("	and len(pad.placeholderdata) > 5 ");
                    Proc.Append("	and pad.placeholderdata <> '<P>&nbsp;</P>' ");
                    Proc.Append("	ORDER BY t.placeholdernumber ");
                    Proc.Append(" ");
                    Proc.Append("ELSE ");
                    Proc.Append("BEGIN ");
                    Proc.Append(" ");
                    Proc.Append("	SELECT	 ");
                    Proc.Append("		RTRIM(th.templatename) as templatename,  ");
                    Proc.Append("		th.numberofplaceholders,  ");
                    Proc.Append("		t.placeholdernumber,  ");
                    Proc.Append("		RTRIM(t.fieldname) as fieldname, ");
                    Proc.Append("		t.fieldtype, ");
                    Proc.Append("		t.fieldheight, ");
                    Proc.Append("		t.fieldwidth, ");
                    Proc.Append("		page.title, ");
                    Proc.Append("		pad.placeholderdata, ");
                    Proc.Append("		t.id as templatefieldid, ");
                    Proc.Append("		t.showname ");
                    Proc.Append("	FROM template_header as th ");
                    Proc.Append("		LEFT JOIN templates as t on t.templateid = th.templateid ");
                    Proc.Append("		LEFT JOIN page as page on page.templateid = t.templateid  ");
                    Proc.Append("		LEFT JOIN page_archive_data as pad on pad.pageid = page.pageid ");
                    Proc.Append("	WHERE t.templateid = @templateid ");
                    Proc.Append("	and page.pageid = @pageid ");
                    Proc.Append("	and pad.placeholdernumber = t.placeholdernumber ");
                    Proc.Append("	and pad.pagerevision = @revision ");
                    Proc.Append("	and len(pad.placeholderdata) > 5 ");
                    Proc.Append("	and pad.placeholderdata <> '<P>&nbsp;</P>' ");
                    Proc.Append("	ORDER BY t.placeholdernumber ");
                    Proc.Append(" ");
                    Proc.Append("END ");
                }

                if(Provider == DBUtility.Providers.MySQL)
                {
                    Proc.Append("CALL usp_get_pagearchivedetails(@pageid);");
                }

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder GetPagePreviewDetails
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                if(Provider == DBUtility.Providers.SqlServer)
                {
                    Proc.Append("DECLARE @CNT int, @templateid uniqueidentifier ");
                    Proc.Append(" ");
                    Proc.Append("SELECT @templateid = templateid ");
                    Proc.Append("FROM page ");
                    Proc.Append("WHERE pageid = @pageid ");
                    Proc.Append(" ");
                    Proc.Append("SELECT @CNT = COUNT(*)  ");
                    Proc.Append("FROM page_working_data  ");
                    Proc.Append("WHERE pageid = @pageid ");
                    Proc.Append(" ");
                    Proc.Append("IF @CNT = 0 ");
                    Proc.Append(" ");
                    Proc.Append("	SELECT	 ");
                    Proc.Append("		RTRIM(th.templatename) as templatename,  ");
                    Proc.Append("		th.numberofplaceholders,  ");
                    Proc.Append("		t.placeholdernumber,  ");
                    Proc.Append("		RTRIM(t.fieldname) as fieldname, ");
                    Proc.Append("		t.fieldtype, ");
                    Proc.Append("		t.fieldheight, ");
                    Proc.Append("		t.fieldwidth, ");
                    Proc.Append("		page.title, ");
                    Proc.Append("		awd.placeholderdata, ");
                    Proc.Append("		len(awd.placeholderdata), ");
                    Proc.Append("		t.id as templatefieldid, ");
                    Proc.Append("		t.showname ");
                    Proc.Append("	FROM template_header as th ");
                    Proc.Append("		LEFT JOIN templates as t on t.templateid = th.templateid ");
                    Proc.Append("		LEFT JOIN page as page on page.templateid = t.templateid  ");
                    Proc.Append("		LEFT JOIN page_working_data as awd on awd.pageid = page.pageid ");
                    Proc.Append("	WHERE t.templateid = @templateid ");
                    Proc.Append("	and page.pageid = @pageid ");
                    Proc.Append("	and len(awd.placeholderdata) > 5 ");
                    Proc.Append("	and awd.placeholderdata <> '<P>&nbsp;</P>' ");
                    Proc.Append("	ORDER BY t.placeholdernumber ");
                    Proc.Append(" ");
                    Proc.Append("ELSE ");
                    Proc.Append("BEGIN ");
                    Proc.Append(" ");
                    Proc.Append("	SELECT	 ");
                    Proc.Append("		RTRIM(th.templatename) as templatename,  ");
                    Proc.Append("		th.numberofplaceholders,  ");
                    Proc.Append("		t.placeholdernumber,  ");
                    Proc.Append("		RTRIM(t.fieldname) as fieldname, ");
                    Proc.Append("		t.fieldtype, ");
                    Proc.Append("		t.fieldheight, ");
                    Proc.Append("		t.fieldwidth, ");
                    Proc.Append("		page.title, ");
                    Proc.Append("		awd.placeholderdata, ");
                    Proc.Append("		len(awd.placeholderdata), ");
                    Proc.Append("		t.id as templatefieldid, ");
                    Proc.Append("		t.showname ");
                    Proc.Append("	FROM template_header as th ");
                    Proc.Append("		LEFT JOIN templates as t on t.templateid = th.templateid ");
                    Proc.Append("		LEFT JOIN page as page on page.templateid = t.templateid  ");
                    Proc.Append("		LEFT JOIN page_working_data as awd on awd.pageid = page.pageid ");
                    Proc.Append("	WHERE t.templateid = @templateid ");
                    Proc.Append("	and page.pageid = @pageid ");
                    Proc.Append("	and awd.placeholdernumber = t.placeholdernumber ");
                    Proc.Append("	and len(awd.placeholderdata) > 5 ");
                    Proc.Append("	and awd.placeholderdata <> '<P>&nbsp;</P>' ");
                    Proc.Append("	ORDER BY t.placeholdernumber ");
                    Proc.Append(" ");
                    Proc.Append("END ");
                }

                if(Provider == DBUtility.Providers.MySQL)
                {
                    Proc.Append("CALL usp_get_pagepreviewdetails(@pageid);");
                }

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder GetPageViewDetails
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                if(Provider == DBUtility.Providers.SqlServer)
                {
                    Proc.Append("DECLARE @CNT int, @templateid uniqueidentifier ");
                    Proc.Append(" ");
                    Proc.Append("SELECT @templateid = templateid ");
                    Proc.Append("FROM page ");
                    Proc.Append("WHERE pageid = @pageid ");
                    Proc.Append(" ");
                    Proc.Append("SELECT @CNT = COUNT(*)  ");
                    Proc.Append("FROM page_final_data  ");
                    Proc.Append("WHERE pageid = @pageid ");
                    Proc.Append(" ");
                    Proc.Append("IF @CNT = 0 ");
                    Proc.Append(" ");
                    Proc.Append("	SELECT	 ");
                    Proc.Append("		RTRIM(th.templatename) as templatename,  ");
                    Proc.Append("		th.numberofplaceholders,  ");
                    Proc.Append("		t.placeholdernumber,  ");
                    Proc.Append("		RTRIM(t.fieldname) as fieldname, ");
                    Proc.Append("		t.fieldtype, ");
                    Proc.Append("		t.fieldheight, ");
                    Proc.Append("		t.fieldwidth, ");
                    Proc.Append("		page.title, ");
                    Proc.Append("		afd.placeholderdata, ");
                    Proc.Append("		t.id as templatefieldid, ");
                    Proc.Append("		t.showname ");
                    Proc.Append("	FROM template_header as th ");
                    Proc.Append("		LEFT JOIN templates as t on t.templateid = th.templateid ");
                    Proc.Append("		LEFT JOIN page as page on page.templateid = t.templateid  ");
                    Proc.Append("		LEFT JOIN page_final_data as afd on afd.pageid = page.pageid ");
                    Proc.Append("	WHERE t.templateid = @templateid ");
                    Proc.Append("	and page.pageid = @pageid ");
                    Proc.Append("	and len(afd.placeholderdata) > 5 ");
                    Proc.Append("	and afd.placeholderdata <> '<P>&nbsp;</P>' ");
                    Proc.Append("	ORDER BY t.placeholdernumber ");
                    Proc.Append(" ");
                    Proc.Append("ELSE ");
                    Proc.Append("BEGIN ");
                    Proc.Append(" ");
                    Proc.Append("	SELECT	 ");
                    Proc.Append("		RTRIM(th.templatename) as templatename,  ");
                    Proc.Append("		th.numberofplaceholders,  ");
                    Proc.Append("		t.placeholdernumber,  ");
                    Proc.Append("		RTRIM(t.fieldname) as fieldname, ");
                    Proc.Append("		t.fieldtype, ");
                    Proc.Append("		t.fieldheight, ");
                    Proc.Append("		t.fieldwidth, ");
                    Proc.Append("		page.title, ");
                    Proc.Append("		afd.placeholderdata, ");
                    Proc.Append("		t.id as templatefieldid, ");
                    Proc.Append("		t.showname ");
                    Proc.Append("	FROM template_header as th ");
                    Proc.Append("		LEFT JOIN templates as t on t.templateid = th.templateid ");
                    Proc.Append("		LEFT JOIN page as page on page.templateid = t.templateid  ");
                    Proc.Append("		LEFT JOIN page_final_data as afd on afd.pageid = page.pageid ");
                    Proc.Append("	WHERE t.templateid = @templateid ");
                    Proc.Append("	and page.pageid = @pageid ");
                    Proc.Append("	and afd.placeholdernumber = t.placeholdernumber ");
                    Proc.Append("	and len(afd.placeholderdata) > 5 ");
                    Proc.Append("	and afd.placeholderdata <> '<P>&nbsp;</P>' ");
                    Proc.Append("	ORDER BY t.placeholdernumber ");
                    Proc.Append(" ");
                    Proc.Append("END ");
                }

                if(Provider == DBUtility.Providers.MySQL)
                {
                    Proc.Append("CALL usp_get_pagefinaldetails(@pageid);");
                }

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder GetPageByPageID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("pageid,  ");
                Proc.Append("kbid,  ");
                Proc.Append("createdate,  ");
                Proc.Append("publishdate,  ");
                Proc.Append("expiredate,  ");
                Proc.Append("statusdate,  ");
                Proc.Append("currentuserid,  ");
                Proc.Append("title,  ");
                Proc.Append("iv_access_type,  ");
                Proc.Append("iv_level,  ");
                Proc.Append("iv_status,  ");
                Proc.Append("iv_priority,  ");
                Proc.Append("keywords,  ");
                Proc.Append("pagerevision,  ");
                Proc.Append("iv_itemtype,  ");
                Proc.Append("accesstype,  ");
                Proc.Append("difficultylevel, ");
                Proc.Append("status,  ");
                Proc.Append("priority,  ");
                Proc.Append("itemtype,  ");
                Proc.Append("summary,  ");
                Proc.Append("templateid,  ");
                Proc.Append("spotlight, ");
                Proc.Append("iv_itemtype, ");
                Proc.Append("userid, ");
                Proc.Append("dbo.fn_comment_count(pageid) as comments, ");
                Proc.Append("dbo.fn_view_count(pageid) as views, ");
                Proc.Append("IsNull(dbo.fn_rank_count(pageid), 0) as rank ");
                Proc.Append("FROM vw_page_list  ");
                Proc.Append("WHERE pageid = @pageid ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder InsertPage
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("INSERT INTO page ");
                Proc.Append("( ");
                Proc.Append("pageid, ");
                Proc.Append("publishdate, ");
                Proc.Append("expiredate, ");
                Proc.Append("title, ");
                Proc.Append("iv_access_type, ");
                Proc.Append("iv_level, ");
                Proc.Append("iv_status, ");
                Proc.Append("templateid, ");
                Proc.Append("keywords, ");
                Proc.Append("pagerevision, ");
                Proc.Append("iv_itemtype, ");
                Proc.Append("spotlight, ");
                Proc.Append("userid ");
                Proc.Append(") ");
                Proc.Append("VALUES ");
                Proc.Append("( ");
                Proc.Append("@pageid, ");
                Proc.Append("@publishdate, ");
                Proc.Append("@expiredate, ");
                Proc.Append("@title, ");
                Proc.Append("@iv_access_type, ");
                Proc.Append("@iv_level, ");
                Proc.Append("@iv_status, ");
                Proc.Append("@templateid, ");
                Proc.Append("@keywords, ");
                Proc.Append("@revision, ");
                Proc.Append("@iv_itemtype, ");
                Proc.Append("@spotlight, ");
                Proc.Append("@userid ");
                Proc.Append("); ");
                Proc.Append(" ");
                Proc.Append("INSERT INTO page_summary ");
                Proc.Append("( ");
                Proc.Append("pageid, ");
                Proc.Append("summary ");
                Proc.Append(") ");
                Proc.Append("VALUES ");
                Proc.Append("( ");
                Proc.Append("@pageid, ");
                Proc.Append("@summary ");
                Proc.Append("); ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder UpdatePage
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("UPDATE page SET ");
                Proc.Append("publishdate = @publishdate, ");
                Proc.Append("expiredate = @expiredate, ");
                Proc.Append("title = @title, ");
                Proc.Append("iv_access_type = @iv_access_type, ");
                Proc.Append("iv_level = @iv_level, ");
                Proc.Append("iv_status = @iv_status, ");
                Proc.Append("templateid = @templateid, ");
                Proc.Append("keywords = @keywords, ");
                Proc.Append("pagerevision = @revision, ");
                Proc.Append("iv_itemtype = @iv_itemtype, ");
                Proc.Append("spotlight = @spotlight ");
                Proc.Append("WHERE pageid = @pageid; "); 
                Proc.Append(" ");
                Proc.Append("UPDATE page_summary SET ");
                Proc.Append("summary = @summary  ");
                Proc.Append("WHERE pageid = @pageid; ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder DeletePage
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("DELETE FROM page_working_data WHERE pageid = @pageid; ");
                Proc.Append("DELETE FROM page_archive_data WHERE pageid = @pageid; ");
                Proc.Append("DELETE FROM page_final_data WHERE pageid = @pageid; ");
                Proc.Append("DELETE FROM page_summary WHERE pageid = @pageid; ");
                Proc.Append("DELETE FROM page WHERE pageid = @pageid; ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder GetPageLockByPageID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("pageid,   ");
                Proc.Append("currentuserid  ");
                Proc.Append("FROM vw_page_list  ");
                Proc.Append("WHERE pageid = @pageid ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder InsertPageLock
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("UPDATE PAGE ");
                Proc.Append("SET currentuserid = @userid ");
                Proc.Append("WHERE pageid = @pageid ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder UpdatePageLock
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("UPDATE PAGE ");
                Proc.Append("SET currentuserid = @userid ");
                Proc.Append("WHERE pageid = @pageid ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder DeletePageLock
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("UPDATE PAGE ");
                Proc.Append("SET currentuserid = null ");
                Proc.Append("WHERE pageid = @pageid and currentuserid = @userid ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder CheckForWorkingDataByPageID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                if(Provider == DBUtility.Providers.SqlServer)
                {
                    Proc.Append("SELECT top 1 pageid FROM page_working_data WHERE pageid = @pageid ");
                }

                if(Provider == DBUtility.Providers.MySQL)
                {
                    Proc.Append("SELECT pageid FROM page_working_data WHERE pageid = @pageid LIMIT 1 ");
                }

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder InsertPageWorkingData
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                if(Provider == DBUtility.Providers.SqlServer)
                {
                    Proc.Append("DECLARE @CNT int ");
                    Proc.Append(" ");
                    Proc.Append("SELECT @CNT=COUNT(*) FROM page_working_data ");
                    Proc.Append("WHERE pageid = @pageid and placeholdernumber = @placeholdernumber ");
                    Proc.Append(" ");
                    Proc.Append("IF @CNT = 0 ");
                    Proc.Append(" ");
                    Proc.Append("INSERT INTO page_working_data ");
                    Proc.Append("( ");
                    Proc.Append("	pageid, ");
                    Proc.Append("	placeholdernumber, ");
                    Proc.Append("	placeholderdata, ");
                    Proc.Append("	lastuserid, ");
                    Proc.Append("	pagerevision ");
                    Proc.Append(") ");
                    Proc.Append("VALUES ");
                    Proc.Append("( ");
                    Proc.Append("	@pageid, ");
                    Proc.Append("	@placeholdernumber, ");
                    Proc.Append("	@placeholderdata, ");
                    Proc.Append("	@lastuserid, ");
                    Proc.Append("	@pagerevision ");
                    Proc.Append(") ");
                    Proc.Append(" ");
                    Proc.Append("ELSE ");
                    Proc.Append("BEGIN ");
                    Proc.Append(" ");
                    Proc.Append("UPDATE page_working_data ");
                    Proc.Append("SET	placeholdernumber = @placeholdernumber, ");
                    Proc.Append("	placeholderdata = @placeholderdata, ");
                    Proc.Append("	pagerevision = @pagerevision, ");
                    Proc.Append("	lastuserid = @lastuserid ");
                    Proc.Append("WHERE pageid = @pageid and placeholdernumber = @placeholdernumber ");
                    Proc.Append(" ");
                    Proc.Append("END ");
                }

                if(Provider == DBUtility.Providers.MySQL)
                {
                    Proc.Append("CALL usp_insert_insertpageworkingdata(@pageid, @placeholdernumber, @placeholderdata, @lastuserid, @pagerevision);");
                }

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder UpdatePageWorkingData
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("UPDATE page_working_data ");
                Proc.Append("SET placeholdernumber = @placeholdernumber, ");
                Proc.Append("placeholderdata = @placeholderdata, ");
                Proc.Append("pagerevision = @pagerevision, ");
                Proc.Append("lastuserid = @lastuserid ");
                Proc.Append("WHERE pageid = @pageid and placeholdernumber = @placeholdernumber ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder DeletePageWorkingData
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListPageRevisions
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT DISTINCT pageid, pagerevision, modifydate, lastuserid ");
                Proc.Append("FROM page_archive_data ");
                Proc.Append("WHERE pageid = @pageid ");
                Proc.Append("ORDER BY pagerevision ");

                return FormatSQLStateMents(Proc);
            }
        }

        #endregion

        #region "MSSQL/MySQL Poll Procedure Properties "

        public StringBuilder AllowUserToVote
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("select pollchoice as voted from pollresults where pollid=@PollId and userid=@userid ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder GetPollQuestionByPollID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT pollquestion, expirationdate, userid, createdate, closed, answercount ");
                Proc.Append("FROM pollquestions ");
                Proc.Append("WHERE pollid = @PollId ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder InsertPollQuestion
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("insert into pollquestions ");
                Proc.Append("( ");
                Proc.Append("pollid, ");
                Proc.Append("PollQuestion, ");
                Proc.Append("ExpirationDate, ");
                Proc.Append("UserID, ");
                Proc.Append("CreateDate, ");
                Proc.Append("Closed, ");
                Proc.Append("AnswerCount ");
                Proc.Append(")  ");
                Proc.Append("values ");
                Proc.Append("( ");
                Proc.Append("@pollid, ");
                Proc.Append("@PollQuestion, ");
                Proc.Append("@ExpirationDate, ");
                Proc.Append("@UserID, ");
                Proc.Append("CURRENT_TIMESTAMP, ");
                Proc.Append("0, ");
                Proc.Append("0 ");
                Proc.Append(") ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder UpdatePollQuestion
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("UPDATE pollquestions ");
                Proc.Append("SET PollQuestion = @PollQuestion, ");
                Proc.Append("ExpirationDate = @ExpirationDate  ");
                Proc.Append("WHERE pollid = @pollid ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder DeletePollQuestion
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("delete from pollresults where pollid=@PollId ");
                Proc.Append("delete from pollanswers where pollid=@PollId ");
                Proc.Append("delete from pollquestions where pollid=@PollId ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder GetPollResultByPollID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder InsertPollResult
        {
            get
            {
                StringBuilder Proc = new StringBuilder();                

                Proc.Append("insert into pollresults ( pollid, pollchoice, userid ) values ( @PollId, @PollChoice, @userid ) ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder UpdatePollResult
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder DeletePollResult
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder GetPollAnswerByAnswerID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("select ");
                Proc.Append("	AnswerId,  ");
                Proc.Append("	AnswerText ");
                Proc.Append("from pollanswers  ");
                Proc.Append("where AnswerId=@AnswerID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder InsertPollAnswer
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("insert into pollanswers ");
                Proc.Append("( ");
                Proc.Append("pollid, ");
                Proc.Append("AnswerId,  ");
                Proc.Append("answertext,  ");
                Proc.Append("answercount ");
                Proc.Append(")  ");
                Proc.Append("values ");
                Proc.Append("( ");
                Proc.Append("@PollId,  ");
                Proc.Append("@AnswerId, ");
                Proc.Append("@AnswerText,  ");
                Proc.Append("0  ");
                Proc.Append(") ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder UpdatePollAnswer
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("update pollanswers ");
                Proc.Append("SET answertext = @AnswerText ");
                Proc.Append("WHERE answerid = @answerid ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder DeletePollAnswer
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("delete from pollanswers WHERE answerid = @answerid ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListPollResults
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                if(Provider == DBUtility.Providers.SqlServer)
                {
                    Proc.Append("SELECT ");
                    Proc.Append("	pa.answertext,  ");
                    Proc.Append("	pa.answercount,  ");
                    Proc.Append("(CASE WHEN pa.answercount = 0 THEN 0 ELSE Convert(decimal, ((pa.answercount/pq.answercount) * 100)) END) as votepercentage ");
                    Proc.Append("FROM pollquestions as pq ");
                    Proc.Append("join pollanswers as pa on pa.pollid = pq.pollid ");
                    Proc.Append("WHERE pq.pollid = @pollid ");
                    Proc.Append("ORDER BY pa.answertext ");
                }

                if(Provider == DBUtility.Providers.MySQL)
                {
                    Proc.Append("SELECT ");
                    Proc.Append("pa.answertext,  ");
                    Proc.Append("pa.answercount,  ");
                    Proc.Append("CASE WHEN pa.answercount = 0 THEN 0 ELSE CAST(((pa.answercount/pq.answercount) * 100) As Decimal) END as votepercentage ");
                    Proc.Append("FROM pollquestions as pq ");
                    Proc.Append("join pollanswers as pa on pa.pollid = pq.pollid ");
                    Proc.Append("WHERE pq.pollid = ?pollid ");
                    Proc.Append("ORDER BY pa.answertext ");
                }

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListPollQuestions
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("Pollid,  ");
                Proc.Append("PollQuestion,  ");
                Proc.Append("ExpirationDate,   ");
                Proc.Append("CreateDate,  ");
                Proc.Append("UserID, ");
                Proc.Append("Closed,  ");
                Proc.Append("AnswerCount, ");
                Proc.Append("dbo.fn_comment_count(Pollid) as comments, ");
                Proc.Append("dbo.fn_view_count(Pollid) as views, ");
                Proc.Append("IsNull(dbo.fn_rank_count(Pollid), 0) as rank ");
                Proc.Append("FROM pollquestions ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListPollsByUser
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("Pollid, ");
                Proc.Append("PollQuestion, ");
                Proc.Append("ExpirationDate, ");
                Proc.Append("CreateDate, ");
                Proc.Append("UserID, ");
                Proc.Append("Closed, ");
                Proc.Append("AnswerCount, ");
                Proc.Append("dbo.fn_comment_count(Pollid) as comments, ");
                Proc.Append("dbo.fn_view_count(Pollid) as views, ");
                Proc.Append("IsNull(dbo.fn_rank_count(Pollid), 0) as rank ");
                Proc.Append("FROM pollquestions ");
                Proc.Append("WHERE userid = @userid ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListPollsAnswers
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT PollId, AnswerId, AnswerText, AnswerCount ");
                Proc.Append("FROM pollanswers  ");
                Proc.Append("WHERE pollid=@PollId ");
                Proc.Append("ORDER BY answertext ");

                return FormatSQLStateMents(Proc);
            }
        }

        //Mimic Triggers that are in MSSQL
        public StringBuilder UpdateVoteCountOnResultInsert
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("update pollanswers set answercount=( select count(*) from pollresults where pollid=@PollId and pollchoice=@AnswerId) where pollid=@PollId and AnswerId=@AnswerId; ");
                Proc.Append("update pollquestions set answercount=( select count(*) from pollresults where pollid=@PollId) where pollid=@PollId; ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder UpdateVoteCountOnAnswerDelete
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("delete from pollresults where pollid=@PollId and PollChoice=@AnswerId; ");
                Proc.Append("update pollquestions set answercount=(select count(*) from pollresults where pollid=@PollId) where pollid=@PollId; ");

                return FormatSQLStateMents(Proc);
            }
        }

        #endregion

        #region "MSSQL/MySQL Rank Procedure Properties "

        public StringBuilder GetRankByItemID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("rank  ");
                Proc.Append("FROM ranks  ");
                Proc.Append("WHERE itemid = @itemid  ");
                Proc.Append("and revision = @revision  ");
                Proc.Append("and userid = @userid ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder InsertRank
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                if(Provider == DBUtility.Providers.SqlServer)
                {
                    Proc.Append("DECLARE @currank int, @cnt int, @newrank int, @rev int ");
                    Proc.Append(" ");
                    Proc.Append("SELECT @rev=revision FROM ranks WHERE itemid = @itemid ");
                    Proc.Append("SELECT @currank=AVG(rank) FROM ranks WHERE itemid = @itemid and userid = @userid ");
                    Proc.Append("SELECT @cnt=count(*) FROM ranks WHERE itemid = @itemid ");
                    Proc.Append(" ");
                    Proc.Append(" ");
                    Proc.Append("IF @rev Is Null ");
                    Proc.Append("BEGIN ");
                    Proc.Append(" ");
                    Proc.Append("	IF @cnt = 0 ");
                    Proc.Append("		SET @newrank = @rank ");
                    Proc.Append("	ELSE ");
                    Proc.Append("	BEGIN ");
                    Proc.Append("		SET @newrank = avg(@currank + @rank) ");
                    Proc.Append("	END ");
                    Proc.Append(" ");
                    Proc.Append("	IF @cnt = 0 ");
                    Proc.Append("		INSERT INTO ranks ");
                    Proc.Append("		(id, itemid, userid, rank, revision) ");
                    Proc.Append("		VALUES ");
                    Proc.Append("		(@id, @itemid, @userid, @newrank, @revision) ");
                    Proc.Append("	ELSE ");
                    Proc.Append("	BEGIN ");
                    Proc.Append("		UPDATE ranks SET rank = @newrank, revision = @revision WHERE itemid = @itemid and userid = @userid ");
                    Proc.Append("	END ");
                    Proc.Append(" ");
                    Proc.Append("END ");
                }
                if(Provider == DBUtility.Providers.MySQL)
                {
                    Proc.Append("CALL usp_insert_rank(@id, @itemid, @userid, @rank, @revision);");
                }

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder UpdateRank
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder DeleteRank
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                return FormatSQLStateMents(Proc);
            }
        }

        #endregion

        #region "MSSQL/MySQL Report Procedure Properties "

        public StringBuilder ListTopNItemsByType
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                if(Provider == DBUtility.Providers.SqlServer)
                {
                    Proc.Append("DECLARE @SQL nvarchar(max) ");
                    Proc.Append(" ");
                    Proc.Append("SELECT @SQL =  ");
                    Proc.Append("'SELECT  ");
                    Proc.Append("	top '+convert(nvarchar(max), @numbertodisplay)+'  ");
                    Proc.Append("	linktype, ");
                    Proc.Append("	urlparams,  ");
                    Proc.Append("	item,  ");
                    Proc.Append("	itemid,  ");
                    Proc.Append("	title,  ");
                    Proc.Append("	summary,  ");
                    Proc.Append("	body,  ");
                    Proc.Append("	createdate, ");
                    Proc.Append("	userid, ");
                    Proc.Append("	dbo.fn_comment_count(itemid) as comments, ");
                    Proc.Append("	dbo.fn_view_count(itemid) as views, ");
                    Proc.Append("	IsNull(dbo.fn_rank_count(itemid), 0) as rank, ");
                    Proc.Append("	createdby	   ");
                    Proc.Append("FROM vw_search_items ");
                    Proc.Append("WHERE (linktype = '+convert(nvarchar(max), @itemtype)+' OR '+convert(nvarchar(max), @itemtype)+' = -1) ");
                    Proc.Append("AND private = 0 ");
                    Proc.Append("AND IsApproved = 1 ");
                    Proc.Append("ORDER BY createdate desc' ");
                    Proc.Append(" ");
                    Proc.Append("EXEC sp_executesql @SQL ");
                }

                if(Provider == DBUtility.Providers.MySQL)
                {
                    //Keep this for examples later, since it took awhile to get it right!!
                    //Proc.Append("PREPARE STMT  ");
                    //Proc.Append("FROM ");
                    //Proc.Append("'SELECT  ");
                    //Proc.Append("linktype, ");
                    //Proc.Append("urlparams,  ");
                    //Proc.Append("item,  ");
                    //Proc.Append("itemid,  ");
                    //Proc.Append("title,  ");
                    //Proc.Append("summary,  ");
                    //Proc.Append("body,  ");
                    //Proc.Append("createdate, ");
                    //Proc.Append("userid, ");
                    //Proc.Append("fn_comment_count(itemid) as comments, ");
                    //Proc.Append("fn_view_count(itemid) as views, ");
                    //Proc.Append("IFNULL(fn_rank_count(itemid), 0) as rank ");
                    //Proc.Append("FROM vw_search_items ");
                    //Proc.Append("WHERE (linktype = ? OR ? = -1) ");
                    //Proc.Append("AND private = 0 ");
                    //Proc.Append("ORDER BY createdate DESC ");
                    //Proc.Append("LIMIT ?'; ");
                    //Proc.Append(" ");
                    //Proc.Append("SET @tmpitemtype:= ?itemtype; ");
                    //Proc.Append("SET @tmpnumbertodisplay:= ?numbertodisplay; ");
                    //Proc.Append(" ");
                    //Proc.Append("EXECUTE STMT USING @tmpitemtype, @tmpitemtype, @tmpnumbertodisplay; ");

                    Proc.Append("SELECT  ");
                    Proc.Append("linktype, ");
                    Proc.Append("urlparams,  ");
                    Proc.Append("item,  ");
                    Proc.Append("itemid,  ");
                    Proc.Append("title,  ");
                    Proc.Append("summary,  ");
                    Proc.Append("body,  ");
                    Proc.Append("createdate, ");
                    Proc.Append("userid, ");
                    Proc.Append("fn_comment_count(itemid) as comments, ");
                    Proc.Append("fn_view_count(itemid) as views, ");
                    Proc.Append("IFNULL(fn_rank_count(itemid), 0) as rank ");
                    Proc.Append("FROM vw_search_items ");
                    Proc.Append("WHERE (linktype = ?itemtype OR ?itemtype = -1) ");
                    Proc.Append("AND private = 0 ");
                    Proc.Append("AND IsApproved = 1 ");
                    Proc.Append("ORDER BY createdate DESC ");
                    Proc.Append("LIMIT ?numbertodisplay ");
                }

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListTopNItemsMostViewed
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                if(Provider == DBUtility.Providers.SqlServer)
                {
                    Proc.Append("DECLARE @SQL nvarchar(max) ");
                    Proc.Append(" ");
                    Proc.Append("SELECT @SQL =  ");
                    Proc.Append("'SELECT  ");
                    Proc.Append("	top '+convert(nvarchar(max), @numbertodisplay)+'  ");
                    Proc.Append("	linktype, ");
                    Proc.Append("	urlparams,  ");
                    Proc.Append("	item,  ");
                    Proc.Append("	itemid,  ");
                    Proc.Append("	title,  ");
                    Proc.Append("	summary,  ");
                    Proc.Append("	body,  ");
                    Proc.Append("	createdate, ");
                    Proc.Append("	userid, ");
                    Proc.Append("	dbo.fn_comment_count(itemid) as comments, ");
                    Proc.Append("	dbo.fn_view_count(itemid) as views, ");
                    Proc.Append("	IsNull(dbo.fn_rank_count(itemid), 0) as rank, ");
                    Proc.Append("	createdby	  ");
                    Proc.Append("FROM vw_search_items ");
                    Proc.Append("WHERE (linktype = '+convert(nvarchar(max), @itemtype)+' OR '+convert(nvarchar(max), @itemtype)+' = -1) ");
                    Proc.Append("AND private = 0 ");
                    Proc.Append("AND IsApproved = 1 ");
                    Proc.Append("ORDER BY dbo.fn_view_count(itemid) desc' ");
                    Proc.Append(" ");
                    Proc.Append("EXEC sp_executesql @SQL ");
                }

                if(Provider == DBUtility.Providers.MySQL)
                {
                    Proc.Append("SELECT  ");
                    Proc.Append("linktype, ");
                    Proc.Append("urlparams,  ");
                    Proc.Append("item,  ");
                    Proc.Append("itemid,  ");
                    Proc.Append("title,  ");
                    Proc.Append("summary,  ");
                    Proc.Append("body,  ");
                    Proc.Append("createdate, ");
                    Proc.Append("userid, ");
                    Proc.Append("fn_comment_count(itemid) as comments, ");
                    Proc.Append("fn_view_count(itemid) as views, ");
                    Proc.Append("IFNULL(fn_rank_count(itemid), 0) as rank ");
                    Proc.Append("FROM vw_search_items ");
                    Proc.Append("WHERE (linktype = ?itemtype OR ?itemtype = -1) ");
                    Proc.Append("AND private = 0 ");
                    Proc.Append("AND IsApproved = 1 ");
                    Proc.Append("ORDER BY fn_view_count(itemid) DESC ");
                    Proc.Append("LIMIT ?numbertodisplay ");
                }

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListTopNItemsMostComments
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                if(Provider == DBUtility.Providers.SqlServer)
                {
                    Proc.Append("DECLARE @SQL nvarchar(max) ");
                    Proc.Append(" ");
                    Proc.Append("SELECT @SQL =  ");
                    Proc.Append("'SELECT  ");
                    Proc.Append("	top '+convert(nvarchar(max), @numbertodisplay)+'  ");
                    Proc.Append("	linktype, ");
                    Proc.Append("	urlparams,  ");
                    Proc.Append("	item,  ");
                    Proc.Append("	itemid,  ");
                    Proc.Append("	title,  ");
                    Proc.Append("	summary,  ");
                    Proc.Append("	body,  ");
                    Proc.Append("	createdate, ");
                    Proc.Append("	userid, ");
                    Proc.Append("	dbo.fn_comment_count(itemid) as comments, ");
                    Proc.Append("	dbo.fn_view_count(itemid) as views, ");
                    Proc.Append("	IsNull(dbo.fn_rank_count(itemid), 0) as rank, ");
                    Proc.Append("	createdby	 ");
                    Proc.Append("FROM vw_search_items ");
                    Proc.Append("WHERE (linktype = '+convert(nvarchar(max), @itemtype)+' OR '+convert(nvarchar(max), @itemtype)+' = -1) ");
                    Proc.Append("AND private = 0 ");
                    Proc.Append("AND IsApproved = 1 ");
                    Proc.Append("ORDER BY dbo.fn_comment_count(itemid) desc' ");
                    Proc.Append(" ");
                    Proc.Append("EXEC sp_executesql @SQL ");
                }

                if(Provider == DBUtility.Providers.MySQL)
                {
                    Proc.Append("SELECT  ");
                    Proc.Append("linktype, ");
                    Proc.Append("urlparams,  ");
                    Proc.Append("item,  ");
                    Proc.Append("itemid,  ");
                    Proc.Append("title,  ");
                    Proc.Append("summary,  ");
                    Proc.Append("body,  ");
                    Proc.Append("createdate, ");
                    Proc.Append("userid, ");
                    Proc.Append("fn_comment_count(itemid) as comments, ");
                    Proc.Append("fn_view_count(itemid) as views, ");
                    Proc.Append("IFNULL(fn_rank_count(itemid), 0) as rank ");
                    Proc.Append("FROM vw_search_items ");
                    Proc.Append("WHERE (linktype = ?itemtype OR ?itemtype = -1) ");
                    Proc.Append("AND private = 0 ");
                    Proc.Append("AND IsApproved = 1 ");
                    Proc.Append("ORDER BY fn_comment_count(itemid) DESC ");
                    Proc.Append("LIMIT ?numbertodisplay ");
                }

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListTopNItemsHighestRank
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                if(Provider == DBUtility.Providers.SqlServer)
                {
                    Proc.Append("DECLARE @SQL nvarchar(max) ");
                    Proc.Append(" ");
                    Proc.Append("SELECT @SQL =  ");
                    Proc.Append("'SELECT  ");
                    Proc.Append("	top '+convert(nvarchar(max), @numbertodisplay)+'  ");
                    Proc.Append("	linktype, ");
                    Proc.Append("	urlparams,  ");
                    Proc.Append("	item,  ");
                    Proc.Append("	itemid,  ");
                    Proc.Append("	title,  ");
                    Proc.Append("	summary,  ");
                    Proc.Append("	body,  ");
                    Proc.Append("	createdate, ");
                    Proc.Append("	userid, ");
                    Proc.Append("	dbo.fn_comment_count(itemid) as comments, ");
                    Proc.Append("	dbo.fn_view_count(itemid) as views, ");
                    Proc.Append("	IsNull(dbo.fn_rank_count(itemid), 0) as rank, ");
                    Proc.Append("	createdby  ");
                    Proc.Append("FROM vw_search_items ");
                    Proc.Append("WHERE (linktype = '+convert(nvarchar(max), @itemtype)+' OR '+convert(nvarchar(max), @itemtype)+' = -1) ");
                    Proc.Append("AND private = 0 ");
                    Proc.Append("AND IsApproved = 1 ");
                    Proc.Append("ORDER BY dbo.fn_rank_count(itemid) desc' ");
                    Proc.Append(" ");
                    Proc.Append("EXEC sp_executesql @SQL ");
                }

                if(Provider == DBUtility.Providers.MySQL)
                {
                    Proc.Append("SELECT  ");
                    Proc.Append("linktype, ");
                    Proc.Append("urlparams,  ");
                    Proc.Append("item,  ");
                    Proc.Append("itemid,  ");
                    Proc.Append("title,  ");
                    Proc.Append("summary,  ");
                    Proc.Append("body,  ");
                    Proc.Append("createdate, ");
                    Proc.Append("userid, ");
                    Proc.Append("fn_comment_count(itemid) as comments, ");
                    Proc.Append("fn_view_count(itemid) as views, ");
                    Proc.Append("IFNULL(fn_rank_count(itemid), 0) as rank ");
                    Proc.Append("FROM vw_search_items ");
                    Proc.Append("WHERE (linktype = ?itemtype OR ?itemtype = -1) ");
                    Proc.Append("AND private = 0 ");
                    Proc.Append("AND IsApproved = 1 ");
                    Proc.Append("ORDER BY fn_rank_count(itemid) DESC ");
                    Proc.Append("LIMIT ?numbertodisplay ");
                }

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListTopNExpiredPages
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                if(Provider == DBUtility.Providers.SqlServer)
                {
                    Proc.Append("DECLARE @SQL nvarchar(max) ");
                    Proc.Append(" ");
                    Proc.Append("SELECT @SQL =  ");
                    Proc.Append("'SELECT ");
                    Proc.Append("	top '+convert(nvarchar(max), @numbertodisplay)+'  ");
                    Proc.Append("	v.linktype, ");
                    Proc.Append("	v.urlparams,  ");
                    Proc.Append("	v.item,  ");
                    Proc.Append("	v.itemid,  ");
                    Proc.Append("	v.title,  ");
                    Proc.Append("	v.summary,  ");
                    Proc.Append("	v.body,  ");
                    Proc.Append("	v.createdate, ");
                    Proc.Append("	p.expiredate, ");
                    Proc.Append("	v.userid, ");
                    Proc.Append("	dbo.fn_comment_count(v.itemid) as comments, ");
                    Proc.Append("	dbo.fn_view_count(v.itemid) as views, ");
                    Proc.Append("	IsNull(dbo.fn_rank_count(v.itemid), 0) as rank, ");
                    Proc.Append("	createdby	 ");
                    Proc.Append("FROM vw_search_items AS v ");
                    Proc.Append("JOIN page AS p ON p.pageid = v.itemid ");
                    Proc.Append("WHERE p.expiredate <= CURRENT_TIMESTAMP ");
                    Proc.Append("ORDER BY p.expiredate desc' ");
                    Proc.Append(" ");
                    Proc.Append("EXEC sp_executesql @SQL ");
                }

                if(Provider == DBUtility.Providers.MySQL)
                {
                    Proc.Append("SELECT  ");
                    Proc.Append("v.linktype, ");
                    Proc.Append("v.urlparams,  ");
                    Proc.Append("v.item,  ");
                    Proc.Append("v.itemid,  ");
                    Proc.Append("v.title,  ");
                    Proc.Append("v.summary,  ");
                    Proc.Append("v.body,  ");
                    Proc.Append("v.createdate, ");
                    Proc.Append("p.expiredate, ");
                    Proc.Append("v.userid, ");
                    Proc.Append("fn_comment_count(v.itemid) as comments, ");
                    Proc.Append("fn_view_count(v.itemid) as views, ");
                    Proc.Append("IFNULL(fn_rank_count(v.itemid), 0) as rank ");
                    Proc.Append("FROM vw_search_items AS v ");
                    Proc.Append("JOIN page AS p ON p.pageid = v.itemid ");
                    Proc.Append("WHERE p.expiredate <= CURRENT_TIMESTAMP ");
                    Proc.Append("ORDER BY p.expiredate DESC ");
                    Proc.Append("LIMIT ?numbertodisplay ");
                }

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListRSSByItem
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                if(Provider == DBUtility.Providers.SqlServer)
                {
                    Proc.Append("DECLARE @SQL nvarchar(max) ");
                    Proc.Append(" ");
                    Proc.Append("SELECT @SQL =  ");
                    Proc.Append("'SELECT  ");
                    Proc.Append("	linktype, ");
                    Proc.Append("	urlparams,  ");
                    Proc.Append("	item,  ");
                    Proc.Append("	itemid,  ");
                    Proc.Append("	title,  ");
                    Proc.Append("	summary,  ");
                    Proc.Append("	body,  ");
                    Proc.Append("	createdate, ");
                    Proc.Append("	userid, ");
                    Proc.Append("	dbo.fn_comment_count(itemid) as comments, ");
                    Proc.Append("	dbo.fn_view_count(itemid) as views, ");
                    Proc.Append("	IsNull(dbo.fn_rank_count(itemid), 0) as rank, ");
                    Proc.Append("	createdby	   ");
                    Proc.Append("FROM vw_search_items ");
                    Proc.Append("WHERE (itemid = '''+convert(nvarchar(max), @itemid)+''') ");
                    Proc.Append("AND private = 0 ");
                    Proc.Append("AND IsApproved = 1' ");
                    Proc.Append(" ");
                    Proc.Append("EXEC sp_executesql @SQL ");
                }

                if(Provider == DBUtility.Providers.MySQL)
                {
                    Proc.Append("SELECT  ");
                    Proc.Append("linktype, ");
                    Proc.Append("urlparams,  ");
                    Proc.Append("item,  ");
                    Proc.Append("itemid,  ");
                    Proc.Append("title,  ");
                    Proc.Append("summary,  ");
                    Proc.Append("body,  ");
                    Proc.Append("createdate, ");
                    Proc.Append("userid, ");
                    Proc.Append("fn_comment_count(itemid) as comments, ");
                    Proc.Append("fn_view_count(itemid) as views, ");
                    Proc.Append("IFNULL(fn_rank_count(itemid), 0) as rank ");
                    Proc.Append("FROM vw_search_items ");
                    Proc.Append("WHERE itemid = ?itemid ");
                    Proc.Append("AND private = 0 ");
                    Proc.Append("AND IsApproved = 1 ");
                }

                return FormatSQLStateMents(Proc);
            }
        }

        #endregion

        #region "MSSQL/MySQL Resource Procedure Properties "

        public StringBuilder GetResourceByResourceID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("resourceid,  ");
                Proc.Append("resourcename,  ");
                Proc.Append("resourcesize,  ");
                Proc.Append("resourcedesc,  ");
                Proc.Append("resourcetitle,  ");
                Proc.Append("contenttype,  ");
                Proc.Append("resource,  ");
                Proc.Append("thumbnail,  ");
                Proc.Append("archived,  ");
                Proc.Append("createdate, ");
                Proc.Append("userid, ");
                Proc.Append("dbo.fn_comment_count(resourceid) as comments, ");
                Proc.Append("dbo.fn_view_count(resourceid) as views, ");
                Proc.Append("IsNull(dbo.fn_rank_count(resourceid), 0) as rank ");
                Proc.Append("FROM resources ");
                Proc.Append("WHERE 	resourceid = @resourceid ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder InsertResource
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("INSERT  INTO resources ");
                Proc.Append("( ");
                Proc.Append("resourceid, ");
                Proc.Append("resourcename, ");
                Proc.Append("resourcesize, ");
                Proc.Append("resourcedesc, ");
                Proc.Append("resourcetitle, ");
                Proc.Append("contenttype, ");
                Proc.Append("resource, ");
                Proc.Append("thumbnail, ");
                Proc.Append("private, ");
                Proc.Append("userid ");
                Proc.Append(")  ");
                Proc.Append("VALUES  ");
                Proc.Append("( ");
                Proc.Append("@resourceid, ");
                Proc.Append("@resourcename, ");
                Proc.Append("@resourcesize, ");
                Proc.Append("@resourcedesc, ");
                Proc.Append("@resourcetitle, ");
                Proc.Append("@contenttype, ");
                Proc.Append("@resource, ");
                Proc.Append("@thumbnail, ");
                Proc.Append("@private, ");
                Proc.Append("@userid ");
                Proc.Append("); ");
                Proc.Append(" ");
                Proc.Append("INSERT INTO resources_folders ");
                Proc.Append("( ");
                Proc.Append("resourceid, ");
                Proc.Append("nodeid ");
                Proc.Append(") ");
                Proc.Append("VALUES ");
                Proc.Append("( ");
                Proc.Append("@resourceid, ");
                Proc.Append("@nodeid ");
                Proc.Append("); ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder UpdateResource
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("UPDATE resources SET ");
                Proc.Append("resourcename = @resourcename, ");
                Proc.Append("resourcesize = @resourcesize, ");
                Proc.Append("resourcedesc = @resourcedesc, ");
                Proc.Append("resourcetitle = @resourcetitle, ");
                Proc.Append("contenttype = @contenttype, ");
                Proc.Append("resource = @resource, ");
                Proc.Append("thumbnail = @thumbnail, ");
                Proc.Append("private = @private ");
                Proc.Append("WHERE 	resourceid = @resourceid ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder DeleteResource
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("UPDATE resources SET ");
                Proc.Append("archived = @deleteresource ");
                Proc.Append("WHERE 	resourceid = @resourceid ");

                Proc.Append("DELETE FROM item_resources WHERE resourceid = @resourceid ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder InsertItemResource
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("INSERT INTO item_resources ");
                Proc.Append("( ");
                Proc.Append("itemid, ");
                Proc.Append("resourceid ");
                Proc.Append(") ");
                Proc.Append("VALUES ");
                Proc.Append("( ");
                Proc.Append("@itemid, ");
                Proc.Append("@resourceid ");
                Proc.Append(") ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder UpdateItemResource
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder DeleteItemResource
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("DELETE FROM item_resources ");
                Proc.Append("WHERE itemid = @itemid ");
                Proc.Append("and resourceid = @resourceid ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListResource
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("rf.resourceid,  ");
                Proc.Append("rf.nodeid, ");
                Proc.Append("IsNull(f.name, 'NA') As Folder, ");
                Proc.Append("r.resourcename,  ");
                Proc.Append("r.resourcesize,  ");
                Proc.Append("r.resourcedesc,  ");
                Proc.Append("r.resourcetitle,  ");
                Proc.Append("r.contenttype, ");
                Proc.Append("r.userid, ");
                Proc.Append("dbo.fn_comment_count(r.resourceid) as comments, ");
                Proc.Append("dbo.fn_view_count(r.resourceid) as views, ");
                Proc.Append("IsNull(dbo.fn_rank_count(r.resourceid), 0) as rank, ");
                Proc.Append("r.createdate ");
                Proc.Append("FROM resources_folders as rf ");
                Proc.Append("LEFT JOIN resources as r on r.resourceid = rf.resourceid ");
                Proc.Append("LEFT JOIN folders as f on f.nodeid = rf.nodeid ");
                Proc.Append("WHERE (r.archived = 0 or r.archived is null) ");
                Proc.Append("AND f.userid is not null ");
                Proc.Append("and r.private = 0 ");

                return FormatSQLStateMents(Proc);

            }
        }

        public StringBuilder ListResourceByUserIDNodeID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("rf.resourceid,  ");
                Proc.Append("rf.nodeid,  ");
                Proc.Append("r.resourcename, ");
                Proc.Append("r.resourcesize,  ");
                Proc.Append("r.resourcedesc,  ");
                Proc.Append("r.resourcetitle,  ");
                Proc.Append("r.contenttype, ");
                Proc.Append("r.userid, ");
                Proc.Append("dbo.fn_comment_count(r.resourceid) as comments, ");
                Proc.Append("dbo.fn_view_count(r.resourceid) as views, ");
                Proc.Append("IsNull(dbo.fn_rank_count(r.resourceid), 0) as rank, ");
                Proc.Append("r.createdate ");
                Proc.Append("FROM resources_folders as rf ");
                Proc.Append("JOIN resources as r on r.resourceid = rf.resourceid ");
                Proc.Append("JOIN folders as f on f.nodeid = rf.nodeid ");
                Proc.Append("WHERE f.nodeid = @nodeid  ");
                Proc.Append("and f.userid = @userid ");
                Proc.Append("and (r.archived = 0 or r.archived is null) ");
                Proc.Append("and r.private = 0 ");

                return FormatSQLStateMents(Proc);

            }
        }

        public StringBuilder ListResourceByNodeID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("rf.resourceid,  ");
                Proc.Append("rf.nodeid,  ");
                Proc.Append("r.resourcename, ");
                Proc.Append("r.resourcesize,  ");
                Proc.Append("r.resourcedesc,  ");
                Proc.Append("r.resourcetitle,  ");
                Proc.Append("r.contenttype, ");
                Proc.Append("r.userid, ");
                Proc.Append("dbo.fn_comment_count(r.resourceid) as comments, ");
                Proc.Append("dbo.fn_view_count(r.resourceid) as views, ");
                Proc.Append("IsNull(dbo.fn_rank_count(r.resourceid), 0) as rank, ");
                Proc.Append("r.createdate ");
                Proc.Append("FROM resources_folders as rf ");
                Proc.Append("JOIN resources as r on r.resourceid = rf.resourceid ");
                Proc.Append("WHERE nodeid = @nodeid and (archived = 0 or archived is null) ");

                return FormatSQLStateMents(Proc);

            }
        }

        public StringBuilder ListResourceByUserID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("rf.resourceid,  ");
                Proc.Append("rf.nodeid,  ");
                Proc.Append("r.resourcename, ");
                Proc.Append("r.resourcesize,  ");
                Proc.Append("r.resourcedesc,  ");
                Proc.Append("r.resourcetitle,  ");
                Proc.Append("r.contenttype, ");
                Proc.Append("r.userid, ");
                Proc.Append("dbo.fn_comment_count(r.resourceid) as comments, ");
                Proc.Append("dbo.fn_view_count(r.resourceid) as views, ");
                Proc.Append("IsNull(dbo.fn_rank_count(r.resourceid), 0) as rank, ");
                Proc.Append("r.createdate ");
                Proc.Append("FROM resources_folders as rf ");
                Proc.Append("JOIN resources as r on r.resourceid = rf.resourceid ");
                Proc.Append("JOIN folders as f on f.nodeid = rf.nodeid ");
                Proc.Append("WHERE f.userid = @userid ");
                Proc.Append("and (r.archived = 0 or r.archived is null) ");
                Proc.Append("and r.private = 0 ");

                return FormatSQLStateMents(Proc);

            }
        }

        public StringBuilder ListResourcesByItemID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("ir.resourceid,  ");
                Proc.Append("r.resourcename,  ");
                Proc.Append("r.resourcesize,  ");
                Proc.Append("r.resourcedesc,  ");
                Proc.Append("r.resourcetitle,  ");
                Proc.Append("r.contenttype, ");
                Proc.Append("dbo.fn_comment_count(r.resourceid) as comments, ");
                Proc.Append("dbo.fn_view_count(r.resourceid) as views, ");
                Proc.Append("IsNull(dbo.fn_rank_count(r.resourceid), 0) as rank, ");
                Proc.Append("userid ");
                Proc.Append("FROM item_resources as ir ");
                Proc.Append("JOIN resources as r on r.resourceid = ir.resourceid ");
                Proc.Append("WHERE  itemid = @itemid  ");
                Proc.Append("and (archived = 0 or archived is null) ");

                return FormatSQLStateMents(Proc);

            }
        }

        #endregion

        #region "MSSQL/MySQL Security Procedure Properties "

        public StringBuilder GetSecurityByID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("secureitemid, ");
                Proc.Append("rolename ");
                Proc.Append("FROM security ");
                Proc.Append("WHERE id = @id ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder InsertSecurity
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("INSERT INTO security ( ");
                Proc.Append("id, ");
                Proc.Append("secureitemid, ");
                Proc.Append("rolename ");
                Proc.Append(") VALUES ( ");
                Proc.Append("@id, ");
                Proc.Append("@secureitemid, ");
                Proc.Append("@rolename ");
                Proc.Append(") ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder UpdateSecurity
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("UPDATE security SET ");
                Proc.Append("secureitemid = @secureitemid,	 ");
                Proc.Append("rolename = @rolename ");
                Proc.Append("WHERE id = @id ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder DeleteSecurity
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("DELETE FROM security WHERE id = @id ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListSecurity
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("id, ");
                Proc.Append("secureitemid, ");
                Proc.Append("rolename ");
                Proc.Append("FROM security ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListSecurityByItemID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("id, ");
                Proc.Append("secureitemid, ");
                Proc.Append("rolename ");
                Proc.Append("FROM security ");
                Proc.Append("WHERE secureitemid = @secureitemid ");

                return FormatSQLStateMents(Proc);
            }
        }

        #endregion

        #region "MSSQL/MySQL SlideShow Procedure Properties "

        public StringBuilder ListSlideShow
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT rf.resourceid ");
                Proc.Append("FROM resources_folders AS rf  ");
                Proc.Append("JOIN folders AS f ON f.nodeid = rf.nodeid ");
                Proc.Append("JOIN resources AS r on r.resourceid = rf.resourceid  ");
                Proc.Append("WHERE f.name = 'slideshow' AND f.userid IS NULL AND r.archived = 0 ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListSlideShowByUser
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT rf.resourceid ");
                Proc.Append("FROM resources_folders AS rf  ");
                Proc.Append("JOIN folders AS f ON f.nodeid = rf.nodeid  ");
                Proc.Append("JOIN resources AS r on r.resourceid = rf.resourceid  ");
                Proc.Append("WHERE f.name = 'slideshow' AND f.userid = @userid AND r.archived = 0 ");

                return FormatSQLStateMents(Proc);
            }
        }

        #endregion

        #region "MSSQL/MySQL Subscription Procedure Properties "

        public StringBuilder GetSubscriptionsByUserID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("subscriptionid, ");
                Proc.Append("userid, ");
                Proc.Append("itemid, ");
                Proc.Append("notify, ");
                Proc.Append("archived, ");
                Proc.Append("iv_subscriptiontype ");
                Proc.Append("FROM subscriptions ");
                Proc.Append("WHERE itemid = @itemid ");
                Proc.Append("and userid = @userid ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder InsertSubscriptions
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("INSERT INTO subscriptions ( ");
                Proc.Append("subscriptionid, ");
                Proc.Append("userid, ");
                Proc.Append("itemid, ");
                Proc.Append("notify, ");
                Proc.Append("archived, ");
                Proc.Append("iv_subscriptiontype ");
                Proc.Append(") VALUES ( ");
                Proc.Append("@subscriptionid, ");
                Proc.Append("@userid, ");
                Proc.Append("@itemid, ");
                Proc.Append("@notify, ");
                Proc.Append("@archived, ");
                Proc.Append("@ivsubscriptiontype ");
                Proc.Append(") ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder UpdateSubscriptions
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("UPDATE subscriptions SET ");
                Proc.Append("userid = @userid, ");
                Proc.Append("itemid = @itemid, ");
                Proc.Append("notify = @notify, ");
                Proc.Append("archived = @archived, ");
                Proc.Append("iv_subscriptiontype = @ivsubscriptiontype ");
                Proc.Append("WHERE subscriptionid = @subscriptionid ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder DeleteSubscriptions
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("DELETE FROM subscriptions WHERE subscriptionid = @subscriptionid ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListSubscriptions
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("subscriptionid, ");
                Proc.Append("userid, ");
                Proc.Append("itemid, ");
                Proc.Append("notify, ");
                Proc.Append("archived, ");
                Proc.Append("iv_subscriptiontype ");
                Proc.Append("FROM subscriptions ");
                Proc.Append("WHERE itemid = @itemid ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListSubscriptionsByUserID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT s.subscriptionid, s.userid, s.itemid, s.notify, i.title, i.urlparams, i.summary ");
                Proc.Append("FROM subscriptions as s ");
                Proc.Append("JOIN vw_search_items as i on i.itemid = s.itemid ");
                Proc.Append("WHERE s.userid = @userid ");

                return FormatSQLStateMents(Proc);
            }
        }

        #endregion

        #region "MSSQL/MySQL Tag Procedure Properties "

        public StringBuilder GetTagByTagID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder InsertTag
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("INSERT INTO tags ");
                Proc.Append("(tagid, userid, itemid, tagname, archived, iv_tagtype) ");
                Proc.Append("VALUES ");
                Proc.Append("(@tagid, @userid, @itemid, @tagname, @archived, @ivtagtype) ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder UpdateTag
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder DeleteTag
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("DELETE FROM tags ");
                Proc.Append("WHERE tagname = @tagname ");
                Proc.Append("and itemid = @itemid ");
                Proc.Append("and userid = @userid ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListTags
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT DISTINCT count(tagname) as tagcount, tagname ");
                Proc.Append("FROM tags ");
                Proc.Append("WHERE  archived <> 1 ");
                Proc.Append("GROUP BY tagname ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListTagsByItemID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT DISTINCT count(tagname) as tagcount, tagname ");
                Proc.Append("FROM tags ");
                Proc.Append("WHERE itemid = @itemid and archived <> 1 ");
                Proc.Append("GROUP BY tagname, itemid ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListTagsByUserID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT DISTINCT count(tagname) as tagcount, tagname ");
                Proc.Append("FROM tags ");
                Proc.Append("WHERE userid = @userid and archived <> 1 ");
                Proc.Append("GROUP BY tagname, userid ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListTagsByUserIDItemID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT DISTINCT count(tagname) as tagcount, tagname ");
                Proc.Append("FROM tags ");
                Proc.Append("WHERE userid = @userid ");
                Proc.Append("and itemid = @itemid ");
                Proc.Append("and archived <> 1 ");
                Proc.Append("GROUP BY tagname, userid, itemid ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListTagsByName
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT DISTINCT count(tagname) as tagcount, tagname ");
                Proc.Append("FROM tags ");
                Proc.Append("WHERE tagname = @tagname and archived <> 1 ");
                Proc.Append("GROUP BY tagname ");

                return FormatSQLStateMents(Proc);
            }
        }

        #endregion

        #region "MSSQL/MySQL Template Procedure Properties "

        public StringBuilder GetTemplateHeaderByTemplateID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT templatename, numberofplaceholders FROM template_header WHERE templateid = @templateid ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder InsertTemplateHeader
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("INSERT INTO template_header ");
                Proc.Append("( ");
                Proc.Append("templateid, ");
                Proc.Append("templatename, ");
                Proc.Append("numberofplaceholders ");
                Proc.Append(") ");
                Proc.Append("VALUES ");
                Proc.Append("( ");
                Proc.Append("@templateid, ");
                Proc.Append("@templatename, ");
                Proc.Append("@numberofplaceholders ");
                Proc.Append(") ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder UpdateTemplateHeader
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("UPDATE template_header ");
                Proc.Append("SET templatename = @templatename, ");
                Proc.Append("numberofplaceholders = @numberofplaceholders ");
                Proc.Append("WHERE templateid = @templateid ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder DeleteTemplateHeader
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                if(Provider == DBUtility.Providers.SqlServer)
                {
                    Proc.Append("DECLARE @cnt int ");
                    Proc.Append(" ");
                    Proc.Append("SELECT @cnt=dbo.fn_template_usage_count(templateid) FROM template_header ");
                    Proc.Append("WHERE templateid = @templateid ");
                    Proc.Append(" ");
                    Proc.Append("IF @cnt = 0 ");
                    Proc.Append("BEGIN ");
                    Proc.Append("	DELETE FROM template_header ");
                    Proc.Append("	WHERE templateid = @templateid ");
                    Proc.Append(" ");
                    Proc.Append("	DELETE FROM templates ");
                    Proc.Append("	WHERE templateid = @templateid ");
                    Proc.Append("END ");
                }

                if(Provider == DBUtility.Providers.MySQL)
                {
                    Proc.Append("CALL usp_delete_templateheader(@templateid);");
                }

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder GetTemplateByTemplateID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("placeholdernumber, ");
                Proc.Append("fieldname, ");
                Proc.Append("fieldtype, ");
                Proc.Append("fieldheight, ");
                Proc.Append("fieldwidth, ");
                Proc.Append("editortype, ");
                Proc.Append("showname ");
                Proc.Append("FROM templates ");
                Proc.Append("WHERE templateid = @templateid  ");
                Proc.Append("and placeholdernumber = @placeholdernumber ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder InsertTemplate
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                if(Provider == DBUtility.Providers.SqlServer)
                {
                Proc.Append("DECLARE @placeholderid int ");
                Proc.Append(" ");
                Proc.Append("SELECT @placeholderid=(Max(placeholdernumber) + 1)  ");
                Proc.Append("FROM templates  ");
                Proc.Append("WHERE templateid = @templateid ");
                Proc.Append(" ");
                Proc.Append("IF @placeholderid Is Null  ");
                Proc.Append("	SET @placeholdernumber = 1 ");
                Proc.Append("ELSE ");
                Proc.Append("BEGIN ");
                Proc.Append("	SET @placeholdernumber = @placeholderid ");
                Proc.Append("END ");
                Proc.Append(" ");
                Proc.Append("INSERT INTO templates ");
                Proc.Append("( ");
                Proc.Append("	id, ");
                Proc.Append("	templateid, ");
                Proc.Append("	placeholdernumber, ");
                Proc.Append("	fieldname, ");
                Proc.Append("	fieldtype, ");
                Proc.Append("	fieldheight, ");
                Proc.Append("	fieldwidth, ");
                Proc.Append("	editortype, ");
                Proc.Append("	showname ");
                Proc.Append(") ");
                Proc.Append("VALUES ");
                Proc.Append("( ");
                Proc.Append("	@id, ");
                Proc.Append("	@templateid, ");
                Proc.Append("	@placeholdernumber, ");
                Proc.Append("	@fieldname, ");
                Proc.Append("	@fieldtype, ");
                Proc.Append("	@fieldheight, ");
                Proc.Append("	@fieldwidth, ");
                Proc.Append("	@editortype, ");
                Proc.Append("	@showname ");
                Proc.Append(") ");
                }

                if(Provider == DBUtility.Providers.MySQL)
                {
                    Proc.Append("CALL usp_insert_template(@id, @templateid, @placeholdernumber, @fieldname, @fieldtype, @fieldheight, @fieldwidth, @editortype, @showname);");
                }

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder UpdateTemplate
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("UPDATE templates ");
                Proc.Append("SET ");
                Proc.Append("fieldname = @fieldname, ");
                Proc.Append("fieldtype = @fieldtype, ");
                Proc.Append("fieldheight = @fieldheight, ");
                Proc.Append("fieldwidth = @fieldwidth, ");
                Proc.Append("editortype = @editortype, ");
                Proc.Append("showname = @showname ");
                Proc.Append("WHERE templateid = @templateid  ");
                Proc.Append("and placeholdernumber = @placeholdernumber ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder DeleteTemplate
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("DELETE FROM templates ");
                Proc.Append("WHERE templateid = @templateid  ");
                Proc.Append("and placeholdernumber = @placeholdernumber ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListTemplateHeaders
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("templateid,  ");
                Proc.Append("templatename,  ");
                Proc.Append("numberofplaceholders, ");
                Proc.Append("dbo.fn_template_usage_count(templateid) as templateusage ");
                Proc.Append("FROM template_header ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListTemplates
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("t.id, ");
                Proc.Append("th.templateid,  ");
                Proc.Append("t.placeholdernumber, ");
                Proc.Append("t.fieldname, ");
                Proc.Append("t.fieldtype, ");
                Proc.Append("t.fieldheight, ");
                Proc.Append("t.fieldwidth, ");
                Proc.Append("t.editortype, ");
                Proc.Append("t.showname, ");
                Proc.Append("dbo.fn_template_usage_count(th.templateid) as templateusage ");
                Proc.Append("FROM template_header as th ");
                Proc.Append("LEFT JOIN templates as t on t.templateid = th.templateid ");
                Proc.Append("WHERE th.templateid = @templateid ");
                Proc.Append("ORDER BY t.placeholdernumber ASC ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListGeneralTemplates
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("templateid,  ");
                Proc.Append("templatename,  ");
                Proc.Append("numberofplaceholders, ");
                Proc.Append("dbo.fn_template_usage_count(templateid) as templateusage ");
                Proc.Append("FROM template_header ");

                return FormatSQLStateMents(Proc);
            }
        }

        #endregion

        #region "MSSQL/MySQL Theme Procedure Properties "

        public StringBuilder GetThemeByThemeID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT themeid, themename, themefolder, usagecount, archived ");
                Proc.Append("FROM themes ");
                Proc.Append("WHERE themeid = @themeid ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder InsertTheme
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("INSERT INTO themes ");
                Proc.Append("(themeid, themename, themefolder) ");
                Proc.Append("VALUES ");
                Proc.Append("(@themeid, @themename, @themefolder) ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder UpdateTheme
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("UPDATE themes ");
                Proc.Append("SET themename = @themename, themefolder = @themefolder ");
                Proc.Append("WHERE themeid = @themeid ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder DeleteTheme
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("DELETE FROM themes WHERE themeid = @themeid ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListThemes
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT themeid, themename, themefolder, usagecount FROM themes ");

                return FormatSQLStateMents(Proc);
            }
        }

        #endregion

        #region "MSSQL/MySQL Tree Procedure Properties "

        public StringBuilder ListTreeParent
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT f.nodeid, name, ");
                Proc.Append("(SELECT count(*) FROM folders WHERE parentnodeid=f.nodeid) as childnodecount ");
                Proc.Append("FROM folders f ");
                Proc.Append("WHERE parentnodeid IS NULL  ");
                Proc.Append("and (archived = 0 or archived is null) ");
                Proc.Append("and userid is null ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListTreeChildByParentID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT f.nodeid, name, ");
                Proc.Append("(SELECT count(*) FROM folders WHERE parentnodeid=f.nodeid) as childnodecount ");
                Proc.Append("FROM folders f ");
                Proc.Append("WHERE parentnodeid = @parentnodeid   ");
                Proc.Append("and (archived = 0 or archived is null) ");
                Proc.Append("and userid is null ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListMenuParent
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT m.id as nodeid, title as name, url, ");
                Proc.Append("(SELECT count(*) FROM sitemap WHERE parent=m.id) as childnodecount ");
                Proc.Append("FROM sitemap m ");
                Proc.Append("WHERE parent IS NULL ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListMenuChildByParentID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT m.id as nodeid, title as name, url, ");
                Proc.Append("(SELECT count(*) FROM sitemap WHERE parent=m.id) as childnodecount ");
                Proc.Append("FROM sitemap m ");
                Proc.Append("WHERE parent = @parentnodeid ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListTreeParentByUserID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT f.nodeid, name, ");
                Proc.Append("(SELECT count(*) FROM folders WHERE parentnodeid=f.nodeid) as childnodecount ");
                Proc.Append("FROM folders f ");
                Proc.Append("WHERE parentnodeid IS NULL  ");
                Proc.Append("and (archived = 0 or archived is null) ");
                Proc.Append("and userid = @userid ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListTreeChildByParentIDUserID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT f.nodeid, name, ");
                Proc.Append("(SELECT count(*) FROM folders WHERE parentnodeid=f.nodeid) as childnodecount ");
                Proc.Append("FROM folders f ");
                Proc.Append("WHERE parentnodeid = @parentnodeid   ");
                Proc.Append("and (archived = 0 or archived is null) ");
                Proc.Append("and userid = @userid ");

                return FormatSQLStateMents(Proc);
            }
        }

        #endregion

        #region "MSSQL/MySQL Views Procedure Properties "

        public StringBuilder GetViewsByItemID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder InsertViews
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                if(Provider == DBUtility.Providers.SqlServer)
                {
                    Proc.Append("DECLARE @viewed int ");
                    Proc.Append(" ");
                    Proc.Append("SELECT @viewed=(Max(viewcount) + 1) FROM views WHERE itemid = @itemid ");
                    Proc.Append(" ");
                    Proc.Append("IF @viewed Is Null ");
                    Proc.Append("	SET @viewed = 1 ");
                    Proc.Append("ELSE ");
                    Proc.Append("BEGIN ");
                    Proc.Append("	SET @viewed = @viewed ");
                    Proc.Append("END ");
                    Proc.Append(" ");
                    Proc.Append("IF @viewed = 1 ");
                    Proc.Append("	INSERT INTO views ");
                    Proc.Append("	(itemid, viewcount) ");
                    Proc.Append("	VALUES ");
                    Proc.Append("	(@itemid, @viewed) ");
                    Proc.Append("ELSE ");
                    Proc.Append("BEGIN ");
                    Proc.Append("	UPDATE views SET viewcount = @viewed WHERE itemid = @itemid ");
                    Proc.Append("END ");
                }

                if(Provider == DBUtility.Providers.MySQL)
                {
                    Proc.Append("CALL usp_update_viewcount(@itemid); ");
                }

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder UpdateViews
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder DeleteViews
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                return FormatSQLStateMents(Proc);
            }
        }

        #endregion

        #region "MSSQL/MySQL Workflow Procedure Properties "

        public StringBuilder MovePageDataToLive
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                if(Provider == DBUtility.Providers.SqlServer)
                {
                    Proc.Append("DECLARE @pagerevision int ");
                    Proc.Append(" ");
                    Proc.Append("SELECT @pagerevision=max(pagerevision)+1 FROM page WHERE pageid = @pageid ");
                    Proc.Append("UPDATE page SET pagerevision=@pagerevision, iv_status=6 WHERE pageid = @pageid ");
                    Proc.Append("UPDATE page_working_data SET pagerevision=@pagerevision WHERE pageid = @pageid ");
                    Proc.Append(" ");
                    Proc.Append("DECLARE @pageid_tmp uniqueidentifier ");
                    Proc.Append("DECLARE @placeholdernumber_tmp int ");
                    Proc.Append("DECLARE @placeholderdata_tmp varchar(MAX) ");
                    Proc.Append("DECLARE @lastuserid_tmp uniqueidentifier ");
                    Proc.Append("DECLARE @pagerevision_tmp int ");
                    Proc.Append(" ");
                    Proc.Append("SET @placeholdernumber_tmp = -1 ");
                    Proc.Append("SET @placeholderdata_tmp  = '' ");
                    Proc.Append("SET @pagerevision_tmp = -1 ");
                    Proc.Append(" ");
                    Proc.Append("DECLARE page_detail_cursor CURSOR FOR ");
                    Proc.Append("SELECT pageid, placeholdernumber, placeholderdata, lastuserid, pagerevision FROM page_working_data WHERE pageid = @pageid ");
                    Proc.Append(" ");
                    Proc.Append("OPEN page_detail_cursor ");
                    Proc.Append(" ");
                    Proc.Append("FETCH NEXT FROM page_detail_cursor ");
                    Proc.Append("INTO @pageid_tmp, @placeholdernumber_tmp, @placeholderdata_tmp, @lastuserid_tmp, @pagerevision_tmp ");
                    Proc.Append(" ");
                    Proc.Append("WHILE @@FETCH_STATUS = 0 ");
                    Proc.Append("BEGIN ");
                    Proc.Append(" ");
                    Proc.Append(" 	DECLARE @cnt int ");
                    Proc.Append("	SELECT @cnt=COUNT(*) FROM page_final_data WHERE pageid = @pageid_tmp and placeholdernumber = @placeholdernumber_tmp ");
                    Proc.Append(" ");
                    Proc.Append("	IF @cnt = 0 ");
                    Proc.Append("			INSERT INTO page_final_data ");
                    Proc.Append("			(pageid, placeholdernumber, placeholderdata, lastuserid, pagerevision) ");
                    Proc.Append("			VALUES ");
                    Proc.Append("			(@pageid_tmp, @placeholdernumber_tmp, @placeholderdata_tmp, @lastuserid_tmp, @pagerevision_tmp) ");
                    Proc.Append("	ELSE ");
                    Proc.Append("	BEGIN ");
                    Proc.Append("			UPDATE page_final_data SET	placeholdernumber = @placeholdernumber_tmp, ");
                    Proc.Append("				placeholderdata = @placeholderdata_tmp, ");
                    Proc.Append("				pagerevision = @pagerevision_tmp, ");
                    Proc.Append("				lastuserid = @lastuserid_tmp ");
                    Proc.Append("			WHERE pageid = @pageid_tmp and placeholdernumber = @placeholdernumber_tmp ");
                    Proc.Append("	END ");
                    Proc.Append(" ");
                    Proc.Append("	FETCH NEXT FROM page_detail_cursor ");
                    Proc.Append("	INTO @pageid_tmp, @placeholdernumber_tmp, @placeholderdata_tmp, @lastuserid_tmp, @pagerevision_tmp ");
                    Proc.Append("END ");
                    Proc.Append(" ");
                    Proc.Append("CLOSE page_detail_cursor ");
                    Proc.Append("DEALLOCATE page_detail_cursor ");
                    Proc.Append(" ");
                    Proc.Append("INSERT INTO page_archive_data ");
                    Proc.Append("(id, pageid, modifydate, placeholdernumber, placeholderdata, lastuserid, pagerevision) ");
                    Proc.Append("SELECT  ");
                    Proc.Append("	newid(),  ");
                    Proc.Append("	pageid, ");
                    Proc.Append("	modifydate,  ");
                    Proc.Append("	placeholdernumber,  ");
                    Proc.Append("	placeholderdata,  ");
                    Proc.Append("	lastuserid,  ");
                    Proc.Append("	pagerevision  ");
                    Proc.Append("FROM page_final_data  ");
                    Proc.Append("WHERE pageid = @pageid ");
                }
                if(Provider == DBUtility.Providers.MySQL)
                {
                    Proc.Append("CALL usp_movepagedata_tolive(@pageid);");
                }

                return FormatSQLStateMents(Proc);
            }
        }

        #endregion

        #region "MSSQL/MySQL Purge Items "

        private StringBuilder PurgeItems
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                //Remove item_resource links when a resource is deleted
                Proc.Append("DELETE FROM item_resources WHERE itemid = @itemid ");

                //Remove subscriptions links when a item is deleted
                Proc.Append("DELETE FROM subscriptions WHERE itemid = @itemid ");

                //Remove views count when an item is deleted
                Proc.Append("DELETE FROM views WHERE itemid = @itemid ");

                //Remove ranks count when an item is deleted
                Proc.Append("DELETE FROM ranks WHERE itemid = @itemid ");

                //Remove tags when an item is deleted
                Proc.Append("DELETE FROM tags WHERE itemid = @itemid ");

                //Remove comments when an item is deleted
                Proc.Append("DELETE FROM comments WHERE itemid = @itemid ");

                //Remove options configuration when an item is deleted
                Proc.Append("DELETE FROM Options WHERE itemid = @itemid ");

                //Remove security configuration when an item is deleted
                Proc.Append("DELETE FROM security WHERE secureitemid = @itemid ");

                return FormatSQLStateMents(Proc);
            }
        }

        public void PurgeItemsByItemID(Guid ItemID)
        {
            DAL.CreateDBObjects(ConnectionString, Provider);

            DAL.AddParameter("@itemid", ItemID);

            DAL.ExecuteNonQuery(PurgeItems.ToString().Trim(), System.Data.CommandType.Text, System.Data.ConnectionState.Open);
        }

        #endregion

        #region "MSSQL/MySQL - Recheck Search Procedure Properties "

        public StringBuilder SearchItems
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                if(Provider == DBUtility.Providers.SqlServer)
                {
                    Proc.Append("DECLARE @SQL nvarchar(max) ");
                    Proc.Append(" ");
                    Proc.Append("SELECT @SQL = ");
                    Proc.Append("'SELECT ");
                    Proc.Append("	urlparams,  ");
                    Proc.Append("	linktype,  ");
                    Proc.Append("	item,  ");
                    Proc.Append("	itemid, ");
                    Proc.Append("	title, ");
                    Proc.Append("	summary, ");
                    Proc.Append("	body, ");
                    Proc.Append("	spotlight, ");
                    Proc.Append("	createdate, ");
                    Proc.Append("	private, ");
                    Proc.Append("	dbo.fn_comment_count(itemid) as comments, ");
                    Proc.Append("	dbo.fn_view_count(itemid) as views, ");
                    Proc.Append("	IsNull(dbo.fn_rank_count(itemid), 0) as rank ");
                    Proc.Append("FROM vw_search_items ");
                    Proc.Append("WHERE (title like ''%'+ @whereclause +'%'' OR body like ''%'+ @whereclause +'%'') ");
                    Proc.Append("and linktype in (1, 2, 3, 4, 5, 6, 7) ");
                    Proc.Append("ORDER by spotlight desc' ");
                    Proc.Append(" ");
                    Proc.Append("EXEC sp_executesql @SQL ");

                }

                if(Provider == DBUtility.Providers.MySQL)
                {
                    Proc.Append("SET @sql = CONCAT('SELECT ");
                    Proc.Append("urlparams, ");
                    Proc.Append("linktype, ");
                    Proc.Append("item, ");
                    Proc.Append("itemid, ");
                    Proc.Append("title, ");
                    Proc.Append("summary, ");
                    Proc.Append("body, ");
                    Proc.Append("spotlight, ");
                    Proc.Append("createdate, ");
                    Proc.Append("private, ");
                    Proc.Append("fn_comment_count(itemid) as comments, ");
                    Proc.Append("fn_view_count(itemid) as views, ");
                    Proc.Append("IFNULL(fn_rank_count(itemid), 0) as rank ");
                    Proc.Append("FROM vw_search_items ");
                    Proc.Append("WHERE title like ''%',?whereclause ,'%'' OR body like ''%',?whereclause ,'%'' and linktype in (1, 2, 3, 4, 5, 6, 7 ) ORDER by spotlight desc'); ");
                    Proc.Append(" ");
                    Proc.Append("PREPARE STMT  FROM @sql; ");
                    Proc.Append(" ");
                    Proc.Append("EXECUTE stmt; ");
                }

                return Proc;
            }
        }

        public StringBuilder SearchItemsByTag
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                if(Provider == DBUtility.Providers.SqlServer)
                {
                    Proc.Append("DECLARE @SQL nvarchar(max) ");
                    Proc.Append(" ");
                    Proc.Append("SELECT @SQL = ");
                    Proc.Append("'SELECT ");
                    Proc.Append("	DISTINCT ");
                    Proc.Append("	itemid, ");
                    Proc.Append("	urlparams, ");
                    Proc.Append("	linktype,  ");
                    Proc.Append("	item,  ");
                    Proc.Append("	title, ");
                    Proc.Append("	summary, ");
                    Proc.Append("	body, ");
                    Proc.Append("	spotlight, ");
                    Proc.Append("	createdate, ");
                    Proc.Append("	private, ");
                    Proc.Append("	comments, ");
                    Proc.Append("	views, ");
                    Proc.Append("	rank, ");
                    Proc.Append("	createdby ");
                    Proc.Append("FROM vw_search_tags ");
                    Proc.Append("WHERE tagname = '''+@whereclause+''' and linktype in (1, 2, 3, 4, 5, 6, 7 ) ");
                    Proc.Append("ORDER by spotlight desc' ");
                    Proc.Append(" ");
                    Proc.Append("EXEC sp_executesql @SQL ");
                }

                if(Provider == DBUtility.Providers.MySQL)
                {
                    Proc.Append("SET @sql = CONCAT('SELECT ");
                    Proc.Append("urlparams, ");
                    Proc.Append("linktype, ");
                    Proc.Append("item, ");
                    Proc.Append("itemid, ");
                    Proc.Append("title, ");
                    Proc.Append("summary, ");
                    Proc.Append("body, ");
                    Proc.Append("spotlight, ");
                    Proc.Append("createdate, ");
                    Proc.Append("private, ");
                    Proc.Append("fn_comment_count(itemid) as comments, ");
                    Proc.Append("fn_view_count(itemid) as views, ");
                    Proc.Append("IFNULL(fn_rank_count(itemid), 0) as rank ");
                    Proc.Append("FROM vw_search_tags ");
                    Proc.Append("WHERE tagname = ''',?whereclause ,''' and linktype in (1, 2, 3, 4, 5, 6, 7 ) ORDER by spotlight desc'); ");
                    Proc.Append(" ");
                    Proc.Append("PREPARE STMT  FROM @sql; ");
                    Proc.Append(" ");
                    Proc.Append("EXECUTE stmt; ");
                }

                return Proc;
            }
        }

        #endregion

        #region "MSSQL/MySQL Form Procedure Properties "

        public StringBuilder GetFormByFormID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("FormID, ");
                Proc.Append("FormName, ");
                Proc.Append("AllowMultipleResponses, ");
                Proc.Append("CurrentUserID, ");
                Proc.Append("IV_FormType, ");
                Proc.Append("ExpireDate, ");
                Proc.Append("UserID, ");
                Proc.Append("FormCompleteMessage, ");
                Proc.Append("CreateDate, ");
                Proc.Append("ModifiedUserID, ");
                Proc.Append("ModifiedDate, ");
				Proc.Append("RegisteredUserOnly ");
                Proc.Append("FROM form ");
                Proc.Append("WHERE FormID = @FormID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder InsertForm
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("INSERT INTO form ( ");
                Proc.Append("FormID, ");
                Proc.Append("FormName, ");
                Proc.Append("AllowMultipleResponses, ");
                Proc.Append("IV_FormType, ");
                Proc.Append("ExpireDate, ");
                Proc.Append("UserID, ");
                Proc.Append("FormCompleteMessage, ");
                Proc.Append("CreateDate, ");
				Proc.Append("RegisteredUserOnly ");
                Proc.Append(") VALUES ( ");
                Proc.Append("@FormID, ");
                Proc.Append("@FormName, ");
                Proc.Append("@AllowMultipleResponses, ");
                Proc.Append("@IV_FormType, ");
                Proc.Append("@ExpireDate, ");
                Proc.Append("@UserID, ");
                Proc.Append("@FormCompleteMessage, ");
                Proc.Append("@CreateDate, ");
				Proc.Append("@RegisteredUserOnly ");
                Proc.Append(") ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder UpdateForm
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("UPDATE form SET ");
                Proc.Append("FormName = @FormName, ");
                Proc.Append("AllowMultipleResponses = @AllowMultipleResponses, ");
                Proc.Append("IV_FormType = @IV_FormType, ");
                Proc.Append("ExpireDate = @ExpireDate, ");
                Proc.Append("FormCompleteMessage = @FormCompleteMessage, ");
                Proc.Append("ModifiedUserID = @ModifiedUserID, ");
                Proc.Append("ModifiedDate = @ModifiedDate, ");
				Proc.Append("RegisteredUserOnly = @RegisteredUserOnly ");
                Proc.Append("WHERE FormID = @FormID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder DeleteForm
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("DELETE FROM form ");
                Proc.Append("WHERE FormID = @FormID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListForms
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("FormID, ");
                Proc.Append("FormName, ");
                Proc.Append("AllowMultipleResponses, ");
                Proc.Append("CurrentUserID, ");
                Proc.Append("IV_FormType, ");
                Proc.Append("ExpireDate, ");
                Proc.Append("UserID, ");
                Proc.Append("FormCompleteMessage, ");
                Proc.Append("CreateDate, ");
                Proc.Append("ModifiedUserID, ");
                Proc.Append("ModifiedDate, ");
                Proc.Append("(SELECT count(*) FROM form_response WHERE form_response.formid = form.formid) AS ResponseCount, ");
				Proc.Append("RegisteredUserOnly ");				
                Proc.Append("FROM form ");

                return FormatSQLStateMents(Proc);
            }
        }

        #endregion

        #region "MSSQL/MySQL FormControls Procedure Properties "

        public StringBuilder GetFormControlByControlID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("FormControlID, ");
                Proc.Append("ControlType, ");
                Proc.Append("Control, ");
                Proc.Append("ControlName, ");
                Proc.Append("RequiresRows, ");
                Proc.Append("RequiresColumns ");
                Proc.Append("FROM form_controls ");
                Proc.Append("WHERE FormControlID = @FormControlID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder InsertFormControl
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("INSERT INTO form_controls ( ");
                Proc.Append("FormControlID, ");
                Proc.Append("ControlType, ");
                Proc.Append("Control, ");
                Proc.Append("ControlName, ");
                Proc.Append("RequiresRows, ");
                Proc.Append("RequiresColumns ");
                Proc.Append(") VALUES ( ");
                Proc.Append("@FormControlID, ");
                Proc.Append("@ControlType, ");
                Proc.Append("@ControlName, ");
                Proc.Append("@RequiresRows, ");
                Proc.Append("@RequiresColumns ");
                Proc.Append(") ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder UpdateFormControl
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("UPDATE form_controls SET ");
                Proc.Append("ControlType = @ControlType, ");
                Proc.Append("Control = @Control, ");
                Proc.Append("ControlName = @ControlName, ");
                Proc.Append("RequiresRows = @RequiresRows, ");
                Proc.Append("RequiresColumns = @RequiresColumns ");
                Proc.Append("WHERE FormControlID = @FormControlID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder DeleteFormControl
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("DELETE FROM form_controls ");
                Proc.Append("WHERE FormControlID = @FormControlID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListControls
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT formcontrolid, controlname FROM form_controls ORDER BY controlname ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListControlsByFormID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("form_question.formquestionid, ");
                Proc.Append("form_controls.controltype, ");
                Proc.Append("form_controls.control, ");
                Proc.Append("form_controls.controlname, ");
                Proc.Append("form_controls.requiresrows, ");
                Proc.Append("form_controls.requirescolumns, ");
                Proc.Append("form_question.question, ");
                Proc.Append("form_question.formcontrolwidth, ");
                Proc.Append("form_question.formcontrolheight, ");
                Proc.Append("form_question.formcontrolrows, ");
                Proc.Append("form_question.formcontrolcols, ");
                Proc.Append("form_question.formpage, ");
                Proc.Append("form_question.isrequired, ");
                Proc.Append("form_question.requiredtext ");
                Proc.Append("FROM form_controls ");
                Proc.Append("JOIN form_question on form_question.formcontrolid = form_controls.formcontrolid ");
                Proc.Append("WHERE form_question.formid = @FormID ");
                Proc.Append("ORDER BY form_question.SortOrder ASC ");

                return FormatSQLStateMents(Proc);
            }
        }

        #endregion

        #region "MSSQL/MySQL FormAnswer Procedure Properties "

        public StringBuilder GetAnswerByAnswerID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("FormResponseID, ");
                Proc.Append("FormQuestionID, ");
                Proc.Append("FormAnswerID, ");
                Proc.Append("Answer ");
                Proc.Append("FROM ");
                Proc.Append("form_answer ");
                Proc.Append("WHERE FormAnswerID = @FormAnswerID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder GetAnswerByQuestionIDAndResponseID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("FormResponseID, ");
                Proc.Append("FormQuestionID, ");
                Proc.Append("FormAnswerID, ");
                Proc.Append("Answer ");
                Proc.Append("FROM ");
                Proc.Append("form_answer ");
                Proc.Append("WHERE FormQuestionID = @FormQuestionID ");
                Proc.Append("AND FormResponseID = @FormResponseID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder InsertAnswer
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("INSERT INTO form_answer ( ");
                Proc.Append("FormResponseID, ");
                Proc.Append("FormAnswerID, ");
                Proc.Append("FormQuestionID, ");
                Proc.Append("Answer ");
                Proc.Append(") VALUES ( ");
                Proc.Append("@FormResponseID, ");
                Proc.Append("@FormAnswerID, ");
                Proc.Append("@FormQuestionID, ");
                Proc.Append("@Answer ");
                Proc.Append(") ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder UpdateAnswer
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("UPDATE form_answer SET ");
                Proc.Append("FormQuestionID = @FormQuestionID, ");
                Proc.Append("Answer = @Answer ");
                Proc.Append("WHERE ");
                Proc.Append("FormAnswerID = @FormAnswerID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder DeleteAnswer
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("DELETE FROM form_answer ");
                Proc.Append("WHERE ");
                Proc.Append("FormAnswerID = @FormAnswerID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListAnswers
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("FormResponseID, ");
                Proc.Append("FormQuestionID, ");
                Proc.Append("FormAnswerID, ");
                Proc.Append("Answer ");
                Proc.Append("FROM ");
                Proc.Append("form_answer ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListAnswersByFormID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("FormResponseID, ");
                Proc.Append("FormQuestionID, ");
                Proc.Append("FormAnswerID, ");
                Proc.Append("Answer ");
                Proc.Append("FROM form_answer");
                Proc.Append("WHERE formid = @formid ");

                return FormatSQLStateMents(Proc);
            }
        }

        //public StringBuilder UpdateAnswerCountOnAnswerInsert
        //{
        //    get
        //    {
        //        StringBuilder Proc = new StringBuilder();

        //        Proc.Append("update form_answer set answercount=( select count(*) from form_answer where FormQuestionID=@FormQuestionID) where FormQuestionID=@FormQuestionID; ");
        //        Proc.Append("update form_question set answercount=( (select count(*) from form_answer where FormQuestionID=@FormQuestionID) + (select count(*) from form_answerrowcolumn where FormQuestionID=@FormQuestionID)) where FormQuestionID=@FormQuestionID; ");

        //        return FormatSQLStateMents(Proc);
        //    }
        //}

        //public StringBuilder ListAnswerResults
        //{
        //    get
        //    {
        //        StringBuilder Proc = new StringBuilder();

        //        if (Provider == DBUtility.Providers.SqlServer)
        //        {
        //            Proc.Append("SELECT ");
        //            Proc.Append("formid, ");
        //            Proc.Append("sortorder, ");
        //            Proc.Append("question, ");
        //            Proc.Append("ISNull(answercount, 0) answercount, ");
        //            Proc.Append("ISNull(resultpercentage, 0) as resultpercentage ");
        //            Proc.Append("FROM ");
        //            Proc.Append("( ");
        //            Proc.Append("SELECT ");
        //            Proc.Append("DISTINCT ");
        //            Proc.Append("form_question.formid, ");
        //            Proc.Append("form_question.sortorder, ");
        //            Proc.Append("form_question.question,  ");
        //            Proc.Append("form_answer.answercount,  ");
        //            Proc.Append("(CASE WHEN form_answer.answercount = 0 THEN 0 ELSE Convert(decimal, ((form_answer.answercount/form_question.answercount) * 100)) END) as resultpercentage ");
        //            Proc.Append("FROM form_question ");
        //            Proc.Append("join form_answer on form_answer.formquestionid = form_question.formquestionid ");
        //            Proc.Append("WHERE form_question.formid = @formid ");
        //            Proc.Append(" ");
        //            Proc.Append("UNION ALL ");
        //            Proc.Append(" ");
        //            Proc.Append("SELECT ");
        //            Proc.Append("DISTINCT ");
        //            Proc.Append("form_question.formid, ");
        //            Proc.Append("form_question.sortorder, ");
        //            Proc.Append("form_question.question+' : '+form_questionrows.rowchoice as question,  ");
        //            Proc.Append("form_answerrowcolumn.answercount,  ");
        //            Proc.Append("(CASE WHEN form_answerrowcolumn.answercount = 0 THEN 0 ELSE Convert(decimal, ((form_answerrowcolumn.answercount/form_question.answercount) * 100)) END) as resultpercentage ");
        //            Proc.Append("FROM form_question ");
        //            Proc.Append("left join form_questionrows  on form_questionrows.formquestionid = form_question.formquestionid ");
        //            Proc.Append("left join form_answerrowcolumn on form_answerrowcolumn.formrowid = form_questionrows.formrowid ");
        //            Proc.Append("WHERE form_question.formid = @formid ");
        //            Proc.Append(") AS Results ");
        //            Proc.Append("WHERE question IS NOT NULL ");
        //            Proc.Append("ORDER BY sortorder ");
        //        }

        //        if (Provider == DBUtility.Providers.MySQL)
        //        {
        //            Proc.Append("SELECT ");
        //            Proc.Append("formid, ");
        //            Proc.Append("sortorder, ");
        //            Proc.Append("question, ");
        //            Proc.Append("IFNull(answercount, 0) answercount, ");
        //            Proc.Append("IFNull(resultpercentage, 0) as resultpercentage ");
        //            Proc.Append("FROM ");
        //            Proc.Append("( ");
        //            Proc.Append("SELECT ");
        //            Proc.Append("DISTINCT ");
        //            Proc.Append("form_question.formid, ");
        //            Proc.Append("form_question.sortorder, ");
        //            Proc.Append("form_question.question,  ");
        //            Proc.Append("form_answer.answercount,  ");
        //            Proc.Append("CASE WHEN form_answer.answercount = 0 THEN 0 ELSE CAST(((form_answer.answercount/form_question.answercount) * 100) As Decimal) END as resultpercentage ");
        //            Proc.Append("FROM form_question ");
        //            Proc.Append("join form_answer on form_answer.formquestionid = form_question.formquestionid ");
        //            Proc.Append("WHERE form_question.formid = ?formid ");
        //            Proc.Append(" ");
        //            Proc.Append("UNION ALL ");
        //            Proc.Append(" ");
        //            Proc.Append("SELECT ");
        //            Proc.Append("DISTINCT ");
        //            Proc.Append("form_question.formid, ");
        //            Proc.Append("form_question.sortorder, ");
        //            Proc.Append("form_question.question+' : '+form_questionrows.rowchoice as question,  ");
        //            Proc.Append("form_answerrowcolumn.answercount,  ");
        //            Proc.Append("CASE WHEN form_answerrowcolumn.answercount = 0 THEN 0 ELSE CAST(((form_answerrowcolumn.answercount/form_question.answercount) * 100) As Decimal) END as resultpercentage ");
        //            Proc.Append("FROM form_question ");
        //            Proc.Append("left join form_questionrows  on form_questionrows.formquestionid = form_question.formquestionid ");
        //            Proc.Append("left join form_answerrowcolumn on form_answerrowcolumn.formrowid = form_questionrows.formrowid ");
        //            Proc.Append("WHERE form_question.formid = ?formid ");
        //            Proc.Append(") AS Results ");
        //            Proc.Append("WHERE question IS NOT NULL ");
        //            Proc.Append("ORDER BY sortorder ");
        //        }

        //        return FormatSQLStateMents(Proc);
        //    }
        //}

        public StringBuilder ListAnswerResult
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("DISTINCT ");
                Proc.Append("(SELECT count(*) FROM form_answer WHERE FormQuestionID = @FormQuestionID) as answercount, ");
                Proc.Append("(SELECT count(*) FROM form_answer WHERE FormQuestionID = @FormQuestionID) as divisor ");
                Proc.Append("FROM form_answer ");
                Proc.Append("WHERE FormQuestionID = @FormQuestionID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListAnswerTextResults
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("FormResponseID, ");
                Proc.Append("Answer ");
                Proc.Append("FROM form_answer ");
                Proc.Append("WHERE FormQuestionID = @FormQuestionID ");

                return FormatSQLStateMents(Proc);
            }
        }

        #endregion

        #region "MSSQL/MySQL FormAnswerRowColumn Procedure Properties "

        public StringBuilder GetFormAnswerRowColumnByAnswerID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("FormResponseID, ");
                Proc.Append("FormQuestionID, ");
                Proc.Append("FormAnswerID, ");
                Proc.Append("FormRowID, ");
                Proc.Append("FormColumnID, ");
                Proc.Append("IsSelected, ");
				Proc.Append("OtherText ");
                Proc.Append("FROM ");
                Proc.Append("form_answerrowcolumn ");
                Proc.Append("WHERE ");
                Proc.Append("FormAnswerID = @FormAnswerID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder GetFormAnswerRowColumnByQuestionIDAndRowIDAndResponseID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("FormResponseID, ");
                Proc.Append("FormQuestionID, ");
                Proc.Append("FormAnswerID, ");
                Proc.Append("FormRowID, ");
                Proc.Append("FormColumnID, ");
                Proc.Append("IsSelected ");
                Proc.Append("FROM ");
                Proc.Append("form_answerrowcolumn ");
                Proc.Append("WHERE ");
                Proc.Append("FormResponseID = @FormResponseID ");
                Proc.Append("AND FormQuestionID = @FormQuestionID ");
                Proc.Append("AND FormRowID = @FormRowID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder GetFormAnswerRowColumnByQuestionIDAndRowIDAndColumnIDAndResponseID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("FormResponseID, ");
                Proc.Append("FormQuestionID, ");
                Proc.Append("FormAnswerID, ");
                Proc.Append("FormRowID, ");
                Proc.Append("FormColumnID, ");
                Proc.Append("IsSelected ");
                Proc.Append("FROM ");
                Proc.Append("form_answerrowcolumn ");
                Proc.Append("WHERE ");
                Proc.Append("FormResponseID = @FormResponseID ");
                Proc.Append("AND FormQuestionID = @FormQuestionID ");
                Proc.Append("AND FormRowID = @FormRowID ");
                Proc.Append("AND FormColumnID = @FormColumnID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder InsertFormAnswerRowColumn
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("INSERT INTO form_answerrowcolumn ( ");
                Proc.Append("FormResponseID, ");
                Proc.Append("FormAnswerID, ");
                Proc.Append("FormQuestionID, ");
                Proc.Append("FormRowID, ");
                Proc.Append("FormColumnID, ");
                Proc.Append("IsSelected, ");
				Proc.Append("OtherText ");
                Proc.Append(") VALUES ( ");
                Proc.Append("@FormResponseID, ");
                Proc.Append("@FormAnswerID, ");
                Proc.Append("@FormQuestionID, ");
                Proc.Append("@FormRowID, ");
                Proc.Append("@FormColumnID, ");
                Proc.Append("@IsSelected, ");
				Proc.Append("@OtherText ");
                Proc.Append(") ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder UpdateFormAnswerRowColumn
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("UPDATE form_answerrowcolumn SET ");
                Proc.Append("FormQuestionID = @FormQuestionID, ");
                Proc.Append("FormRowID = @FormRowID, ");
                Proc.Append("FormColumnID = @FormColumnID, ");
                Proc.Append("IsSelected = @IsSelected, ");
				Proc.Append("OtherText = @OtherText ");
                Proc.Append("WHERE ");
                Proc.Append("FormAnswerID = @FormAnswerID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder DeleteFormAnswerRowColumn
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("DELETE FROM form_answerrowcolumn ");
                Proc.Append("WHERE ");
                Proc.Append("FormAnswerID = @FormAnswerID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListFormAnswerRowColumn
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("FormResponseID, ");
                Proc.Append("FormQuestionID, ");
                Proc.Append("FormAnswerID, ");
                Proc.Append("FormRowID, ");
                Proc.Append("FormColumnID, ");
                Proc.Append("IsSelected ");
                Proc.Append("FROM ");
                Proc.Append("form_answerrowcolumn ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListFormSelectionAnswerResults
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("DISTINCT ");
                Proc.Append("(SELECT count(*) FROM form_answerrowcolumn WHERE FormRowID = @FormRowID) AS answercount, ");
                Proc.Append("(SELECT count(*) FROM form_answerrowcolumn WHERE FormQuestionID = @FormQuestionID) AS divisor ");
                Proc.Append("FROM form_answerrowcolumn ");
                Proc.Append("WHERE formrowid = @FormRowID ");
                Proc.Append("AND formquestionid = @FormQuestionID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListFormMatrixSingleAnswerResults
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("DISTINCT ");
                Proc.Append("( ");
                Proc.Append("	SELECT count(*) FROM form_answerrowcolumn WHERE formcolumnid = @formcolumnid AND formrowid = @formrowid  ");
                Proc.Append(") AS answercount,  ");
                Proc.Append("( ");
                Proc.Append("	SELECT count(*) FROM form_answerrowcolumn WHERE formrowid = @formrowid  ");
                Proc.Append(") AS divisor  ");
                Proc.Append("FROM form_answerrowcolumn  ");
                Proc.Append("WHERE formcolumnid = @FormColumnID  ");
                Proc.Append("AND formrowid = @FormRowID  ");
                Proc.Append("AND formquestionid = @FormQuestionID  ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListFormMatrixMultipleAnswerResults
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("DISTINCT ");
                Proc.Append("( ");
                Proc.Append("	SELECT count(*) FROM form_answerrowcolumn WHERE formcolumnid = @formcolumnid AND formrowid = @formrowid  ");
                Proc.Append(") AS answercount,  ");
                Proc.Append("( ");
                Proc.Append("	SELECT count(*) FROM form_answerrowcolumn WHERE formcolumnid = @formcolumnid  ");
                Proc.Append(") AS divisor  ");
                Proc.Append("FROM form_answerrowcolumn  ");
                Proc.Append("WHERE formcolumnid = @FormColumnID  ");
                Proc.Append("AND formrowid = @FormRowID  ");
                Proc.Append("AND formquestionid = @FormQuestionID  ");

                return FormatSQLStateMents(Proc);
            }
        }

        //public StringBuilder UpdateAnswerCountOnAnswerRowInsert
        //{
        //    get
        //    {
        //        StringBuilder Proc = new StringBuilder();

        //        Proc.Append("update form_answerrowcolumn set answercount=( select count(*) from form_answerrowcolumn where FormQuestionID=@FormQuestionID and FormRowID=@FormRowID) where FormQuestionID=@FormQuestionID and FormRowID=@FormRowID; ");
        //        Proc.Append("update form_question set answercount=( (select count(*) from form_answer where FormQuestionID=@FormQuestionID) + (select count(*) from form_answerrowcolumn where FormQuestionID=@FormQuestionID)) where FormQuestionID=@FormQuestionID; ");

        //        return FormatSQLStateMents(Proc);
        //    }
        //}

        //public StringBuilder UpdateAnswerCountOnAnswerRowColumnInsert
        //{
        //    get
        //    {
        //        StringBuilder Proc = new StringBuilder();

        //        Proc.Append("update form_answerrowcolumn set answercount=( select count(*) from form_answerrowcolumn where FormQuestionID=@FormQuestionID and FormRowID=@FormRowID and FormColumnID=@FormColumnID) where FormQuestionID=@FormQuestionID and FormRowID=@FormRowID and FormColumnID=@FormColumnID; ");
        //        Proc.Append("update form_question set answercount=( (select count(*) from form_answer where FormQuestionID=@FormQuestionID) + (select count(*) from form_answerrowcolumn where FormQuestionID=@FormQuestionID)) where FormQuestionID=@FormQuestionID; ");

        //        return FormatSQLStateMents(Proc);
        //    }
        //}

        #endregion

        #region "MSSQL/MySQL FormQuestion Procedure Properties "

        public StringBuilder GetFormQuestionByQuestionID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("FormID, ");
                Proc.Append("FormQuestionID, ");
                Proc.Append("Question, ");
                Proc.Append("FormControlID, ");
                Proc.Append("FormControlWidth, ");
                Proc.Append("FormControlHeight, ");
                Proc.Append("FormControlRows, ");
                Proc.Append("FormControlCols, ");
                Proc.Append("FormControlLayout, ");
                Proc.Append("FormPage, ");
                Proc.Append("IsRequired, ");
                Proc.Append("RequiredText, ");
                Proc.Append("IsRegularExpressionValidatorRequired, ");
                Proc.Append("RegularExpression, ");
                Proc.Append("RegularExpressionValidatorText, ");
                Proc.Append("IsCompareValidatorRequired, ");
                Proc.Append("CompareValidatorType, ");
                Proc.Append("CompareValidatorText, ");
                Proc.Append("IsRangeValidatorRequired, ");
                Proc.Append("RangeValidatorText, ");
                Proc.Append("RangeStart, ");
                Proc.Append("RangeEnd, ");
                Proc.Append("CreateDate, ");
                Proc.Append("SortOrder, ");
				Proc.Append("IsOtherOption, ");
				Proc.Append("OtherOptionText ");
                Proc.Append("FROM ");
                Proc.Append("form_question ");
                Proc.Append("WHERE ");
                Proc.Append("FormQuestionID = @FormQuestionID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder InsertFormQuestion
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("INSERT INTO form_question ");
                Proc.Append("( ");
                Proc.Append("FormID, ");
                Proc.Append("FormQuestionID, ");
                Proc.Append("Question, ");
                Proc.Append("FormControlID, ");
                Proc.Append("FormControlWidth, ");
                Proc.Append("FormControlHeight, ");
                Proc.Append("FormControlRows, ");
                Proc.Append("FormControlCols, ");
                Proc.Append("FormControlLayout, ");
                Proc.Append("FormPage, ");
                Proc.Append("IsRequired, ");
                Proc.Append("RequiredText, ");
                Proc.Append("IsRegularExpressionValidatorRequired, ");
                Proc.Append("RegularExpression, ");
                Proc.Append("RegularExpressionValidatorText, ");
                Proc.Append("IsCompareValidatorRequired, ");
                Proc.Append("CompareValidatorType, ");
                Proc.Append("CompareValidatorText, ");
                Proc.Append("IsRangeValidatorRequired, ");
                Proc.Append("RangeValidatorText, ");
                Proc.Append("RangeStart, ");
                Proc.Append("RangeEnd, ");
                Proc.Append("CreateDate, ");
                Proc.Append("SortOrder, ");
				Proc.Append("IsOtherOption, ");
				Proc.Append("OtherOptionText ");
                Proc.Append(") ");
                Proc.Append("VALUES ");
                Proc.Append("( ");
                Proc.Append("@FormID, ");
                Proc.Append("@FormQuestionID, ");
                Proc.Append("@Question, ");
                Proc.Append("@FormControlID, ");
                Proc.Append("@FormControlWidth, ");
                Proc.Append("@FormControlHeight, ");
                Proc.Append("@FormControlRows, ");
                Proc.Append("@FormControlCols, ");
                Proc.Append("@FormControlLayout, ");
                Proc.Append("@FormPage, ");
                Proc.Append("@IsRequired, ");
                Proc.Append("@RequiredText, ");
                Proc.Append("@IsRegularExpressionValidatorRequired, ");
                Proc.Append("@RegularExpression, ");
                Proc.Append("@RegularExpressionValidatorText, ");
                Proc.Append("@IsCompareValidatorRequired, ");
                Proc.Append("@CompareValidatorType, ");
                Proc.Append("@CompareValidatorText, ");
                Proc.Append("@IsRangeValidatorRequired, ");
                Proc.Append("@RangeValidatorText, ");
                Proc.Append("@RangeStart, ");
                Proc.Append("@RangeEnd, ");
                Proc.Append("@CreateDate, ");
                Proc.Append("0, ");
				Proc.Append("@IsOtherOption, ");
				Proc.Append("@OtherOptionText ");
                Proc.Append("); ");
                Proc.Append("update form_question set sortorder = (Select IsNull(Max(SortOrder + 1), 1) from form_question) where formquestionid = @FormQuestionID; ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder UpdateFormQuestion
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("UPDATE form_question SET ");
                Proc.Append("FormID = @FormID, ");
                Proc.Append("Question = @Question, ");
                Proc.Append("FormControlID = @FormControlID, ");
                Proc.Append("FormControlWidth = @FormControlWidth, ");
                Proc.Append("FormControlHeight = @FormControlHeight, ");
                Proc.Append("FormControlRows = @FormControlRows, ");
                Proc.Append("FormControlCols = @FormControlCols, ");
                Proc.Append("FormControlLayout = @FormControlLayout, ");
                Proc.Append("FormPage = @FormPage, ");
                Proc.Append("IsRequired = @IsRequired, ");
                Proc.Append("RequiredText = @RequiredText, ");
                Proc.Append("IsRegularExpressionValidatorRequired = @IsRegularExpressionValidatorRequired, ");
                Proc.Append("RegularExpression = @RegularExpression, ");
                Proc.Append("RegularExpressionValidatorText = @RegularExpressionValidatorText, ");
                Proc.Append("IsCompareValidatorRequired = @IsCompareValidatorRequired, ");
                Proc.Append("CompareValidatorType = @CompareValidatorType, ");
                Proc.Append("CompareValidatorText = @CompareValidatorText, ");
                Proc.Append("IsRangeValidatorRequired = @IsRangeValidatorRequired, ");
                Proc.Append("RangeValidatorText = @RangeValidatorText, ");
                Proc.Append("RangeStart = @RangeStart, ");
                Proc.Append("RangeEnd = @RangeEnd, ");
                Proc.Append("SortOrder = @SortOrder, ");
				Proc.Append("IsOtherOption = @IsOtherOption, ");
				Proc.Append("OtherOptionText = @OtherOptionText ");
                Proc.Append("WHERE ");
                Proc.Append("FormQuestionID = @FormQuestionID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder DeleteFormQuestion
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("DELETE FROM form_question ");
                Proc.Append("WHERE ");
                Proc.Append("FormQuestionID = @FormQuestionID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListFormQuestions
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("FormID, ");
                Proc.Append("FormQuestionID, ");
                Proc.Append("Question, ");
                Proc.Append("FormControlID, ");
                Proc.Append("FormControlWidth, ");
                Proc.Append("FormControlHeight, ");
                Proc.Append("FormControlRows, ");
                Proc.Append("FormControlCols, ");
                Proc.Append("FormControlLayout, ");
                Proc.Append("FormPage, ");
                Proc.Append("IsRequired, ");
                Proc.Append("RequiredText, ");
                Proc.Append("IsRegularExpressionValidatorRequired, ");
                Proc.Append("RegularExpression, ");
                Proc.Append("RegularExpressionValidatorText, ");
                Proc.Append("IsCompareValidatorRequired, ");
                Proc.Append("CompareValidatorType, ");
                Proc.Append("CompareValidatorText, ");
                Proc.Append("IsRangeValidatorRequired, ");
                Proc.Append("RangeValidatorText, ");
                Proc.Append("RangeStart, ");
                Proc.Append("RangeEnd, ");
                Proc.Append("CreateDate, ");
                Proc.Append("SortOrder ");
                Proc.Append("FROM ");
                Proc.Append("form_question ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListFormQuestionsByFormID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("FormID, ");
                Proc.Append("FormQuestionID, ");
                Proc.Append("Question, ");
                Proc.Append("FormControlID, ");
                Proc.Append("FormControlWidth, ");
                Proc.Append("FormControlHeight, ");
                Proc.Append("FormControlRows, ");
                Proc.Append("FormControlCols, ");
                Proc.Append("FormControlLayout, ");
                Proc.Append("FormPage, ");
                Proc.Append("IsRequired, ");
                Proc.Append("RequiredText, ");
                Proc.Append("IsRegularExpressionValidatorRequired, ");
                Proc.Append("RegularExpression, ");
                Proc.Append("RegularExpressionValidatorText, ");
                Proc.Append("IsCompareValidatorRequired, ");
                Proc.Append("CompareValidatorType, ");
                Proc.Append("CompareValidatorText, ");
                Proc.Append("IsRangeValidatorRequired, ");
                Proc.Append("RangeValidatorText, ");
                Proc.Append("RangeStart, ");
                Proc.Append("RangeEnd, ");
                Proc.Append("CreateDate, ");
                Proc.Append("SortOrder ");
                Proc.Append("FROM ");
                Proc.Append("form_question ");
                Proc.Append("WHERE formid = @formid ");
                Proc.Append("ORDER BY SortOrder ASC ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder DeleteAnswersOnQuestionDelete
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("delete from form_answer where FormQuestionID=@FormQuestionID; ");
                Proc.Append("delete from form_answerrowcolumn where FormQuestionID=@FormQuestionID; ");
                Proc.Append("delete from form_questioncolumns where FormQuestionID=@FormQuestionID; ");
                Proc.Append("delete from form_questionrows where FormQuestionID=@FormQuestionID; ");

                return FormatSQLStateMents(Proc);
            }
        }

        #endregion

        #region "MSSQL/MySQL FormQuestionColumns Procedure Properties "

        public StringBuilder GetFormQuestionColumnsByQuestionID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("FormQuestionID, ");
                Proc.Append("FormColumnID, ");
                Proc.Append("ColumnChoice, ");
                Proc.Append("CreateDate, ");
                Proc.Append("SortOrder ");
                Proc.Append("FROM ");
                Proc.Append("form_questioncolumns ");
                Proc.Append("WHERE ");
                Proc.Append("FormColumnID = @FormColumnID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder InsertFormQuestionColumns
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("INSERT INTO form_questioncolumns ( ");
                Proc.Append("FormColumnID, ");
                Proc.Append("FormQuestionID, ");
                Proc.Append("ColumnChoice, ");
                Proc.Append("CreateDate, ");
                Proc.Append("SortOrder ");
                Proc.Append(") VALUES ( ");
                Proc.Append("@FormColumnID, ");
                Proc.Append("@FormQuestionID, ");
                Proc.Append("@ColumnChoice, ");
                Proc.Append("@CreateDate, ");
                Proc.Append("0 ");
                Proc.Append("); ");
				Proc.Append("update form_questioncolumns set sortorder = (Select IsNull(Max(SortOrder + 1), 1) from form_questioncolumns) where FormColumnID = @FormColumnID and FormQuestionID = @FormQuestionID; ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder UpdateFormQuestionColumns
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("UPDATE form_questioncolumns SET ");
                Proc.Append("FormQuestionID = @FormQuestionID, ");
                Proc.Append("ColumnChoice = @ColumnChoice, ");
                Proc.Append("SortOrder = @SortOrder ");
                Proc.Append("WHERE ");
                Proc.Append("FormColumnID = @FormColumnID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder DeleteFormQuestionColumns
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("DELETE FROM form_questioncolumns ");
                Proc.Append("WHERE ");
                Proc.Append("FormColumnID = @FormColumnID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListFormQuestionColumns
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("FormQuestionID, ");
                Proc.Append("FormColumnID, ");
                Proc.Append("ColumnChoice, ");
                Proc.Append("CreateDate, ");
                Proc.Append("SortOrder ");
                Proc.Append("FROM ");
                Proc.Append("form_questioncolumns ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListFormQuestionColumnsByQuestionID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("FormQuestionID, ");
                Proc.Append("FormColumnID, ");
                Proc.Append("ColumnChoice, ");
                Proc.Append("CreateDate, ");
                Proc.Append("SortOrder ");
                Proc.Append("FROM form_questioncolumns ");
                Proc.Append("WHERE FormQuestionID = @FormQuestionID ");
                Proc.Append("Order By SortOrder ");

                return FormatSQLStateMents(Proc);
            }
        }

        #endregion

        #region "MSSQL/MySQL FormQuestionRows Procedure Properties "

        public StringBuilder GetFormQuestionRowsByQuestionID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("FormQuestionID, ");
                Proc.Append("FormRowID, ");
                Proc.Append("RowChoice, ");
                Proc.Append("CreateDate, ");
                Proc.Append("SortOrder ");
                Proc.Append("FROM ");
                Proc.Append("form_questionrows ");
                Proc.Append("WHERE ");
                Proc.Append("FormRowID = @FormRowID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder InsertFormQuestionRows
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("INSERT INTO form_questionrows ( ");
                Proc.Append("FormRowID, ");
                Proc.Append("FormQuestionID, ");
                Proc.Append("RowChoice, ");
                Proc.Append("CreateDate, ");
                Proc.Append("SortOrder ");
                Proc.Append(") VALUES ( ");
                Proc.Append("@FormRowID, ");
                Proc.Append("@FormQuestionID, ");
                Proc.Append("@RowChoice, ");
                Proc.Append("@CreateDate, ");
                Proc.Append("0 ");
                Proc.Append("); ");
				Proc.Append("update form_questionrows set sortorder = (Select IsNull(Max(SortOrder + 1), 1) from form_questionrows)where FormRowID = @FormRowID and FormQuestionID = @FormQuestionID; ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder UpdateFormQuestionRows
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("UPDATE form_questionrows SET ");
                Proc.Append("FormQuestionID = @FormQuestionID, ");
                Proc.Append("RowChoice = @RowChoice, ");
                Proc.Append("SortOrder = @SortOrder ");
                Proc.Append("WHERE ");
                Proc.Append("FormRowID = @FormRowID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder DeleteFormQuestionRows
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("DELETE FROM form_questionrows ");
                Proc.Append("WHERE ");
                Proc.Append("FormRowID = @FormRowID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListFormQuestionRows
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("FormQuestionID, ");
                Proc.Append("FormRowID, ");
                Proc.Append("RowChoice, ");
                Proc.Append("CreateDate, ");
                Proc.Append("SortOrder ");
                Proc.Append("FROM ");
                Proc.Append("form_questionrows ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListFormQuestionRowsByQuestionID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("FormQuestionID, ");
                Proc.Append("FormRowID, ");
                Proc.Append("RowChoice, ");
                Proc.Append("CreateDate, ");
                Proc.Append("SortOrder ");
                Proc.Append("FROM form_questionrows ");
                Proc.Append("WHERE FormQuestionID = @FormQuestionID ");
                Proc.Append("Order By SortOrder ");

                return FormatSQLStateMents(Proc);
            }
        }

        #endregion

        #region "MSSQL/MySQL FormResponse Procedure Properties "

        public StringBuilder GetFormResponseByResponseID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("FormID, ");
                Proc.Append("FormResponseID, ");
                Proc.Append("TakenBy, ");
                Proc.Append("TakenDate, ");
                Proc.Append("Reviewed, ");
                Proc.Append("ReviewedBy, ");
                Proc.Append("ReviewerComments, ");
                Proc.Append("ReviewedDate ");
                Proc.Append("FROM form_response ");
                Proc.Append("WHERE FormResponseID = @FormResponseID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder InsertFormResponse
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("INSERT INTO form_response ( ");
                Proc.Append("FormResponseID, ");
                Proc.Append("FormID, ");
                Proc.Append("TakenBy, ");
                Proc.Append("TakenDate ");
                Proc.Append(") VALUES ( ");
                Proc.Append("@FormResponseID, ");
                Proc.Append("@FormID, ");
                Proc.Append("@TakenBy, ");
                Proc.Append("@TakenDate ");
                Proc.Append(") ");

                //Proc.Append("INSERT INTO form_response ( ");
                //Proc.Append("FormResponseID, ");
                //Proc.Append("FormID, ");
                //Proc.Append("TakenBy, ");
                //Proc.Append("TakenDate, ");
                //Proc.Append("Reviewed, ");
                //Proc.Append("ReviewedBy, ");
                //Proc.Append("ReviewerComments, ");
                //Proc.Append("ReviewedDate ");
                //Proc.Append(") VALUES ( ");
                //Proc.Append("@FormResponseID, ");
                //Proc.Append("@FormID, ");
                //Proc.Append("@TakenBy, ");
                //Proc.Append("@TakenDate, ");
                //Proc.Append("@Reviewed, ");
                //Proc.Append("@ReviewedBy, ");
                //Proc.Append("@ReviewerComments, ");
                //Proc.Append("@ReviewedDate ");
                //Proc.Append(") ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder UpdateFormResponse
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("UPDATE form_response SET ");
                Proc.Append("FormID = @FormID, ");
                Proc.Append("TakenBy = @TakenBy, ");
                Proc.Append("TakenDate = @TakenDate, ");
                Proc.Append("Reviewed = @Reviewed, ");
                Proc.Append("ReviewedBy = @ReviewedBy, ");
                Proc.Append("ReviewerComments = @ReviewerComments, ");
                Proc.Append("ReviewedDate = @ReviewedDate ");
                Proc.Append("WHERE FormResponseID = @FormResponseID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder DeleteFormResponse
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("DELETE FROM form_response ");
                Proc.Append("WHERE FormResponseID = @FormResponseID ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListFormResponses
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("form_response.FormID, ");
                Proc.Append("FormResponseID, ");
                Proc.Append("form.formname, ");
                Proc.Append("TakenBy, ");
                Proc.Append("TakenDate, ");
                Proc.Append("Reviewed, ");
                Proc.Append("ReviewedBy, ");
                Proc.Append("ReviewerComments, ");
                Proc.Append("ReviewedDate ");
                Proc.Append("FROM form_response ");
                Proc.Append("JOIN form on form.formid = form_response.formid ");

                return FormatSQLStateMents(Proc);
            }
        }

        public StringBuilder ListFormResponsesByFormID
        {
            get
            {
                StringBuilder Proc = new StringBuilder();

                Proc.Append("SELECT ");
                Proc.Append("form_response.FormID, ");
                Proc.Append("FormResponseID, ");
                Proc.Append("form.formname, ");
                Proc.Append("TakenBy, ");
                Proc.Append("TakenDate, ");
                Proc.Append("Reviewed, ");
                Proc.Append("ReviewedBy, ");
                Proc.Append("ReviewerComments, ");
                Proc.Append("ReviewedDate ");
                Proc.Append("FROM form_response ");
                Proc.Append("JOIN form on form.formid = form_response.formid ");
                Proc.Append("WHERE form_response.FormID = @FormID ");
				Proc.Append("AND (form_response.Reviewed = 0 Or form_response.Reviewed is null )");

                return FormatSQLStateMents(Proc);
            }
        }

        #endregion

        private StringBuilder FormatSQLStateMents(StringBuilder Statement)
        {
            if(Provider == DBUtility.Providers.MySQL)
            {
                Statement.Replace("@", "?");
                Statement.Replace("IsNull", "IFNULL");
                Statement.Replace("dbo.", "");
            }

            return Statement;
        }
    }
}
